1

MongoDB provides a simple REST interface in order for you to send simple queries. The problem is, I don't know how to specify the type when querying. For instance:

Say I have this document in the collection,

 { "_id" : { "$oid" : "51ae1042c92ba30ae0afa26f" }, "serialNumber" : "4661016803", "clientPayload" : { "$binary" : "gwVGYQFoAwEBAQJJkFGj839Ro/N/GcfKG8l89gcAAHvNAAAAAAFDCwADAv+lLwkfAAEACAAAPqQHAAAw7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", "$type" : "00" }, "receiveTime" : { "$date" : 1369717200070 } }

How would I run a query on the serialNumber?

I'm trying

http://xxx.x.x.x:xxxx/test/stuff/?filter_serialNumber=4661016803

But apparently it's running a query for "query" : { "serialNumber" : 4661016803 }

I want "query" : { "serialNumber" : "4661016803" }

4

1 回答 1

5

据我所知,您无法指定值的类型。这似乎是一个错误或限制。如果请求的值以数字开头,它将被解释为数字,而不是字符串。

例如:“abc” -> “abc”,“1abc” -> 1,“123” - 123。

更新:我查找了源代码,\mongodb-src-r2.4.4\src\mongo\db\restapi.cpp:

BSONElement e = i.next();
string name = e.fieldName();
if ( ! name.find( "filter_" ) == 0 )
    continue;

string field = name.substr(7);
const char * val = e.valuestr();

char * temp;

// TODO: this is how i guess if something is a number.  pretty lame right now
double number = strtod( val , &temp );
if ( temp != val )
    queryBuilder.append( field , number );
else
    queryBuilder.append( field , val );
}

查看 TODO 注释和strtod功能 - 这是错误。

于 2013-06-04T19:56:51.200 回答