Mongodb query find with array with interchangin values -


i'm trying figure out if can query document column array.

but if possible if values interchanging. possible search array

with out correctly sorting values? because use parameter later

on update upsert.

it works if do:

players:[ "1","2"] 

but if returns zero:

players:["2","1"] 

document:

{     "_id" : objectid("58218b1709896dabcef00cff"),     "players" : [          "1",          "2"     ],     "total_games" : 1,     "stats" : [          {             "player_id" : "1",             "wins" : 0         },          {             "player_id" : "2",             "wins" : 0         }     ] } 

query (returns 1):

db.getcollection('head_to_head_stats').find({players:[ "1","2"]}) 

query (returns 0):

db.getcollection('head_to_head_stats').find({players:[ "2","1"]}) 

use $all.

the $all operator selects documents value of field array contains specified elements.

db.getcollection('head_to_head_stats').find({players: {$all:[ "2","1"]}}) 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

Laravel mail error `Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]` -

c# SetCompatibleTextRenderingDefault must be called before the first -