我不确定这是否可能。我有books
一个数据结构如下的集合。
{
"_id" : ObjectId("6539d19532f73ad544000001"),
"name" : "PHP",
"books" : [
{"author": "jim", "title" : "Book1", "price":"200"},
{"author": "joe", "title" : "Book2", "price":"300"},
{"author": "amy", "title" : "Book3", "price":"500"}
]
}
现在我想在书籍部分插入一个新对象。该对象类似于{"author": "amy", "title" : "Book4", "price":"400"}
. 所以价格低于 500,所以我想在 Book3 之前插入那个对象。所以我的最终对象将如下所示。
{
"_id" : ObjectId("6539d19532f73ad544000001"),
"name" : "PHP",
"books" : [
{"author": "jim", "title" : "Book1", "price":"200"},
{"author": "joe", "title" : "Book2", "price":"300"},
{"author": "amy", "title" : "Book4", "price":"400"}
{"author": "amy", "title" : "Book3", "price":"500"}
]
}