-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: $regex requires regular expression #125
Comments
@tenjojeremy, the $regex in your code is actually a relaxed extended JSON regular expression. Can you try passing You can get the BSON package from |
hi @edaniels, I tried it like this: import { BSON } from 'mongodb-stitch'
const searchByName = async (data) => {
let db = await MongoConnect(),
collection_users = db.collection('users'),
users
console.log(data.name)
let regxName = new RegExp(data.name)
console.log(regxName)
let bsonRegex = BSON.BSONRegExp(regxName, 'i')
console.log(bsonRegex)
try {
users = await collection_users.find({ name: bsonRegex }).execute()
console.log(users)
return users
} catch (error) {
return error
}
} I dont get an error now, but instead I am getting all the users even if they dont match the pattern. |
What's the pattern? Have you tried the same pattern in the mongo shell? |
My pattern is /hay/ and it works in the mongo shell and it still doesent work let bsonRegex = BSON.BSONRegExp('hay', 'i') I get this when I console.log(bsonRegex) BSONRegExp {_bsontype: "BSONRegExp", pattern: "", options: ""} |
Try |
@edaniels Yes! that worked. Thank you. |
Woo! We'll publish a new SDK with that fix once the change goes in on the BSON library. Have fun developing! |
I am running into this again. It seems to match none of my records with my regex even though I am passing BSON.BSONRegExp() but I am using the server-sdk. Works fine inside of mongo-shell and when I serialize the whole query using JSON.stringify() it does look correct: |
The text was updated successfully, but these errors were encountered: