Java MongoDB driver can't parse query - mongodb

I'm developing project with hibernate-ogm 5 with mongodb 3. But some query can not parsed. But I tested this query on shell. It works. What's wrong with this query?
com.mongodb.util.JSONParseException:
db.Tree.update({'_id':2},{'$inc':{'totalUserCount':NumberInt(-1)}},{})
^
com.mongodb.util.JSONParser.parse(JSON.java:230)
com.mongodb.util.JSONParser.parse(JSON.java:155)
com.mongodb.util.JSON.parse(JSON.java:92)
com.mongodb.util.JSON.parse(JSON.java:73)
org.hibernate.ogm.datastore.mongodb.query.parsing.nativequery.impl.MongoDBQueryDescriptorBuilder.build(MongoDBQueryDescriptorBuilder.java:71)

FYI, the parsing issue will be fixed in the next release of OGM.
Note that it will support NumberLong but not NumberInt as NumberInt is not supported by the MongoDB Java Driver: https://jira.mongodb.org/browse/JAVA-2185 .

The use of functions like NumberInt is not supported at the moment.
I've created an issue for it: https://hibernate.atlassian.net/browse/OGM-1027

Related

Which one is the preferred choice Mongodump VS Mongoexport for upgrading mongoDB database?

My customer uses mongoDB 2.4 and as there are some limitations with this version, we have give them the option to upgrade to Latest stable mongoDB 3.4.5.
Initial testing of using
mongodump in MongoDB 2.4
and mongorestore in Mongodb 3.4.5 worked fine as I can see all the collections imported.
From the documentation mongorestore it was not mentioned anywhere that it can restore the dumps from older versions of mongoDB.
As we cannot use the mongorestore , Can I use "mongoexport" to export the data in csv/json format of older mongoDB 2.4 , and import into newer version of mongoDB 3.4 ?
What are the possible problems of using "mongoexport/mongoimport" instead of "mongodump" to upgrade to newer version of mongoDB 3.4 ?
NOTE: I will remove the older version of mongoDB completely and will install the newer version of mongoDB
Mongodump and Mongorestore are better because:
They run faster
They preserve some data formats better than mongoexport and mongoimport, because the data is not translated from BSON into JSON and back.
As described in the MongoDB Docs on MongoImport:
WARNING
Avoid using mongoimport and mongoexport for full instance production backups. They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON. Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.
In addition, be very careful about the upgrade using mongorestore; just because the data is restored as it was previously, this does not mean that the new version of MongoDB can work with it. For example there were a sequence of changes to the authorisation model after v2.4 which means that you must first upgrade to v2.6, and only then to v3.0. There are similar structural changes at each major version, so it is recommended that you upgrade stepwise, one major version at a time i.e.
v2.4 -> v2.6
v2.6 -> v3.0
v3.0 -> v3.2
v3.2 -> v3.4
From http://www.dba86.com/docs/mongo/2.4/core/import-export.html, mongoexport is supported from 2.4 version. Hence it should be the right tool for that. But still the document has warning message as well.
Warning:
Avoid using mongoimport and mongoexport for full instance production backups. They do not reliably preserve all rich BSON data
types, because JSON can only represent a subset of the types supported
by BSON. Use mongodump and mongorestore as described in MongoDB Backup
Methods for this kind of functionality.
Hope that helps!!!!
Both tools (by default) will just walk the _id index to fetch the data and then write it out to disk. So, yes, both tools will similarly impact your working set which is why I would generally recommend running them against a secondary (preferably a hidden secondary if possible).
I assume you are looking for a mongodump equivalent of the --fields option from mongoexport to only dump out specific fields. The query option can be used to filter results, but it cannot be used with a projection (to select the fields returned) - this is a feature request that is being tracked in TOOLS-28 but is not yet scheduled.

Collection.count() on empty collection in Mongodb

Collection.count() on empty collection in Mongodb is getting hanged and not returning anything
I am using Mongo java driver 3.2 . It is working from CLI.
Any help will be appreciated.

MongoDB "j must be numeric or a boolean value"

I've set up my own local mongodb (v. 3.0.2) instance on a local ubuntu version (14.10) and I'm using genghis(v. 2.3.11) to visualize it. My programm is able to create new documents in the database, but when I try to save a newly created document or delete a document in genghis it always returns "j must be numeric or a boolean value" but it still creates/deletes the document. The error doesn't show up when I edit a document. The only thing I could find when I tried to find a solution on google was this: https://github.com/mongodb/mongo/blob/master/src/mongo/db/write_concern_options.cpp which makes me think that it's a problem with my mongodb setup (and has nothing to do with genghis), but I do not know how to resolve this.
Have you tried running the code against Mongo 2?
I ran into this same error when I tried connecting to Mongo 3 from a service that was using client libraries intended for Mongo 2.

MONGO DB Alias name usage in find query not working

i am using the below command to find records in contacts collection's
db.contacts.find({"field1":"1"})
the problem is i want to use alias name for field1 as SL.NO
i tried this way and its not working...
db.contacts.find({"field :n, as: :SL.NO" : "1"}
can anyne help me in this issue?
BTW I am currently using mongo 1.6.5
Some drivers like Mongoose support that feature, but there is no such feature in MongoDB itself or the Mongo shell.

How to clear/drop/empty a MongoDb collection with Casbah

I started using MongoDb in Scala via Casbah but cannot find on the Casbah documentation / google the way to drop the content of a collection.
The MongoDd doc says the MongoDb shell command to do so is
db.things.remove({});
But how can we achieve the same via Casbah?
Thanks in advance,
Olivier
Casbah's equivalent to the shells {} empty document operator is `MongoDBObject.empty
This should work -
db.things.remove(MongoDBObject.empty)