Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Upsert on _id field with Java driver
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David the Dude  
View profile  
 More options May 10 2012, 1:29 pm
From: David the Dude <ogd...@googlemail.com>
Date: Thu, 10 May 2012 10:29:58 -0700 (PDT)
Local: Thurs, May 10 2012 1:29 pm
Subject: Upsert on _id field with Java driver

Hello,

I can't get an upset to work with the Java driver. The upsert in question
is on an _id which just for testing I set to 1000 for testing purposes.

BasicDBObject findCriterion = new BasicDBObject();
BasicDBObject incClause = new BasicDBObject();
BasicDBObject incDoc = new BasicDBObject();

... I populate the incClause and incDoc, the final query looks like this
(toString)
// findCriterion: { "_id" : 1000}
// incClause: { "total" : 1 , "site.lentreprise|lexpress|fr" : 1}
// incDoc: { "$inc" : { "total" : 1 , "site.lentreprise|lexpress|fr" : 1}}

coll.update(findCriterion, incClause, true, false);

I expect to find something like doc = {'_id' : 1000, "site :
{"lentreprise|express|fr" : 1}, "total" : 1} in the collection but it just
inserts empty documents like { "_id" : ObjectId("4fabf4d7e1bd727dc2fca36d")

}

What do I need to do in order to be able to perform upserts on the  _id
field?

Thanks,

/David


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Hernandez  
View profile  
 More options May 10 2012, 1:43 pm
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Thu, 10 May 2012 10:43:43 -0700
Local: Thurs, May 10 2012 1:43 pm
Subject: Re: [mongodb-user] Upsert on _id field with Java driver
Can you produce the behavior you want in the mongo javascript shell
and post the example?

On Thu, May 10, 2012 at 10:29 AM, David the Dude <ogd...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David the Dude  
View profile  
 More options May 10 2012, 3:52 pm
From: David the Dude <ogd...@googlemail.com>
Date: Thu, 10 May 2012 12:52:36 -0700 (PDT)
Local: Thurs, May 10 2012 3:52 pm
Subject: Re: [mongodb-user] Upsert on _id field with Java driver

Sure,

$ mongo test

var myID = new BinData(3, "21ec20203aea1069a2dd08002b30309d");
var mySite = "lentreprise|lexpress|fr";
var incDoc = {};

incDoc["site." + mySite] = 1;
incDoc["total"] = 1;
db.blah.update({ "_id" : myID }, { $inc : incDoc }, upsert=true);
db.blah.findOne()

{
"_id" : BinData(3,"21ec20203aea1069a2dd08002b30309d"),
"site" : {
"lentreprise|lexpress|fr" : 1

},
"total" : 1
}

I reconstructed the exact same query in Java - the JSON I printed above was
generated by calling .toString() on the DBObjects, yet - using the Java
driver I find it impossible to upsert - at least on "_id" fields. I haven't
found any complaints so I must be doing something wrong.

Thank you,

/David


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David the Dude  
View profile  
 More options May 10 2012, 6:10 pm
From: David the Dude <ogd...@googlemail.com>
Date: Thu, 10 May 2012 15:10:37 -0700 (PDT)
Local: Thurs, May 10 2012 6:10 pm
Subject: Re: [mongodb-user] Upsert on _id field with Java driver

Never mind, it works now - I accidentally cleared incClause and incDoc
before doing the actual upsert.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »