我有一个像bellow
这样的架构的文档{
"Personal":[
{
"name":"Test_Name",
"isActive":true
}
]
}
我正在尝试使用java驱动程序更新此内容。
collections.updateMany(new Document("Personal.name", "Test_Name"), new Document("$set", new Document("Personal.$.isActive", false)))
但不幸的是,这会产生错误
"The positional operator did not find the match needed from the query. Unexpanded update: Personal.$.isActive
“
但是,如果我修改上面的更新过滤器像
collections.updateMany(new Document("Personal.name", "Test_Name"), new Document("$set", new Document("Personal.0.isActive", false)))
它有效。
任何人都可以帮助我理解我在第一次更新声明中使用“$”的错误吗?
这是一些更多的代码spinets
创建集合对象:
collections = mongoConnection.establishConnection()
MongoConnection对象:
public MongoConnection() {
StringBuilder connectionString = new StringBuilder();
connectionString.append("mongodb://url_with_port_and_server")
client = new MongoClient(new MongoClientURI(connectionString.toString()));
db = client.getDatabase("test");
collections = db.getCollection("test");
}
public MongoCollection<Document> establishConnection() {
return collections;
}
public void closeConnection() {
client.close();
}