regex - search all values of list contains in a field of type string in mongodb and in mongodb java -
i have data in mongodb collection named speech field id , speech in following format.
{ "speechtext" : "always boy" }, { "speechtext" : "always guy" }, { "speechtext" : "always cute boy" }, { "speechtext" : "i girl." }
i have fetch data on behalf of 2 keyword 'always be' , 'boy' condition and,or,not.
if condition 'and' search keyword 'always be' , 'boy' result -
{ "speechtext" : "always boy" }, { "speechtext" : "always cute boy" }
if condition 'or' search keyword 'always be' , 'boy' result -
{ "speechtext" : "always boy" }, { "speechtext" : "always guy" }, { "speechtext" : "always cute boy" }
if condition 'not' search keyword 'always be' , 'boy' result -
{ "speechtext" : "i girl." }
i have solution 'or' condition below.
db.getcollection('speech').find({"speechtext" : { "$regex" : "always be|boy"}})
i want query 'and' , not' condition.
here queries 'or', 'and' , 'not' sequencially.
for or -
db.getcollection('speech').find({"speechtext" : { "$regex" : "always be|boy"}})
for , -
db.getcollection('speech').find({$and:[{"speechtext":{$in:[/'always be/]}},{"speechtext":{$in:[/boy/]}}]})
for not -
db.getcollection('speech').find({$or:[{"speechtext":{$nin:[/always be/]}},{"speechtext":{$nin:[/boy/]}}]})
Comments
Post a Comment