07-20-2023, 08:36 AM
1. With Mongoose (and Node), this worked:
- `User.find({ email: /^[email protected]$/i })`
- `User.find({ email: new RegExp(`\`^${emailVariable}$\`, 'i') })
2. In MongoDB, this worked:
- `db.users.find({ email: { $regex: /^[email protected]$/i }})`
Both lines are case-insensitive. The email in the DB could be `[email protected]` and both lines will still find the object in the DB.
Likewise, we could use `/^[email protected]$/i` and it would still find email: `[email protected]` in the DB.
- `User.find({ email: /^[email protected]$/i })`
- `User.find({ email: new RegExp(`\`^${emailVariable}$\`, 'i') })
2. In MongoDB, this worked:
- `db.users.find({ email: { $regex: /^[email protected]$/i }})`
Both lines are case-insensitive. The email in the DB could be `[email protected]` and both lines will still find the object in the DB.
Likewise, we could use `/^[email protected]$/i` and it would still find email: `[email protected]` in the DB.