基于 MongoDB 文档https://docs.mongodb.com/manual/tutorial/query-arrays/ https://docs.mongodb.com/manual/tutorial/query-arrays/
我有这个收藏:
db.inventory.insertMany([
{ item: "journal", qty: 25, tags: ["blank", "red"], dim_cm: [ 14, 21 ] },
{ item: "notebook", qty: 50, tags: ["red", "blank"], dim_cm: [ 14, 21 ] },
{ item: "paper", qty: 100, tags: ["red", "blank", "plain"], dim_cm: [ 14, 21 ] },
{ item: "planner", qty: 75, tags: ["blank", "red"], dim_cm: [ 22.85, 30 ] },
{ item: "postcard", qty: 45, tags: ["blue"], dim_cm: [ 10, 15.25 ] }
]);
这些查询等效吗?
db.inventory.find( { tags: { $all: ["red"] } } )
and
db.inventory.find( { tags: "red" } )
如果它们有不同的目的,什么时候使用其中一个而不是另一个?