test.xxx の内容:
> use test
switched to db test
> db.xxx.find()
{ "_id" : ObjectId("53e4e4983f6dc95697944b74"), "a" : 1 }
{ "_id" : ObjectId("53e4e49a3f6dc95697944b75"), "a" : 2 }
{ "_id" : ObjectId("53e4e49c3f6dc95697944b76"), "a" : 3 }
R セッション:
> library(rmongodb)
> M <- mongo.create("localhost")
> mongo.is.connected(M)
[1] TRUE
>
> qry1 <- list(
+ "a" = 1
+ )
>
> qry2 <- list(
+ "$or" = list(
+ list("a" = 1),
+ list("a" = 3)
+ )
+ )
>
> qry1 <- mongo.bson.from.list(qry1)
> qry2 <- mongo.bson.from.list(qry2)
>
> mongo.count(M, "test.xxx", qry1)
[1] 1
> mongo.count(M, "test.xxx", qry2)
[1] -1
> mongo.get.last.err(M, "test")
connectionId : 16 24
err : 2 $or needs an array
code : 16 2
n : 16 0
ok : 1 1.000000
の結果はqry22 になるはずです。
のリストをどのように言い換える必要がありqry2ますか?
具体的には、mongo.bson.from.json() や「バッファ」から BSON を構築する別の方法ではなく、mongo.bson.from.list() を使用したいと考えています。
次の 3 つの質問は、$or に関するものであり、list() からの BSON の作成に関するものではないことに注意してください。