2016-06-22

MongoDB - String search (similar to SQL's "like")

// Exact match
db.COLLECTION_NAME.find({ "textos.g" : "A phrase" });

// Case sensitive
db.COLLECTION_NAME.find({ "textos.g" : /.*god.*/ });
db.COLLECTION_NAME.find({ "textos.g" : /.*God.*/ });

// Case insensitive
db.COLLECTION_NAME.find({ "textos.g" : /.*god.*/i });

// Starts with
db.COLLECTION_NAME.find({ "textos.g" : /^g/i });

No comments:

Post a Comment