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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -