我使用卡斯巴2.9.2
我的MongoDB的模式是这样的:
[_id: “三角” 信息:颜色: “红色”,行:“薄“,UseID:”1“,SourceId:”2“]]
我希望能够编写一个更新行,首先检查_id,Color和Line是否是唯一的,如果是则更新UseID和SourceID创建一个新的“信息”条目。这让我正是我想要的命令行:
db.shapes.update({ _id : 'Triangle', Info : { $not : { $elemMatch : { Color : 'Red', Line : 'Thick' } } } }, { $push : { Info : { Color : 'Red', Line : 'Thick', UseID : '2', SourceId : '3' } } }, true)
给我这个条目:
[ _id : "Triangle", Info : [ { Color : "Red", Line : "Thin", UseID : "1", SourceId : "2" }, { Color : "Red", Line : "Thick", UseID : "2", SourceId : "3" } ] ]
然而,当我翻译成卡斯巴斯卡拉它并不:
shapesCollection.update({ "_id" -> shape, "Info" $not { _ $elemMatch { "Color" -> color, "Line" -> line } } }, { $push -> { "Info" -> { "Color" -> color, "Line" -> line, "UseId" -> useId, "SourceId" -> srcId } } }, true)
第一个投诉(来自IntelliJ)是希望所有的''都是'',我觉得它是不正确的,但是为了调试我的义务,这使我想到了第二个错误:
“错误:无隐式视图可从(java.lang.String,java.lang.String)=> com.mongodb.casbah.query.Imports.DBObject。涉及默认参数的应用程序中发生错误。 “信息” $ {不_ $ {elemMatch”
所以我想,问题是,我甚至可以做我在卡斯巴在命令行中做更新?如果是这样,怎么样?
谢谢!