2

So, I'm using MongoDB for a project an I have a server that was used to do all the testing for my site and I used DBRef on a few tables and this created something like this:

"comment": { "$ref": "user", "$id": ObjectId("xxxx"), "$db": "dev_server" }

And now we have a new server for the actual production site. Since we where working with real information we exported the DB and placed it into a new one called "prod_server". Now, the DBRef keeps like the one above. I've tried to update the value of the $db but i get this:

"comment": { "$db": "prod_server" "$id": ObjectId("xxxx"), "$ref": "user", }

And with this change the web crashes(mongo changes automatically to alphabetic order). I searched about this and found out that the order of the DBRef is important or else it won't work.

So that why the question: "How to change DBRef" and keep the right order? I used the console and rockmongo for this and none of them worked.

Thank you

Community
  • 1
  • 1
  • Do you really need a DBRef? It doesn't do anything special (other than take up additional space to hold a collection name and server). See docs: http://docs.mongodb.org/manual/reference/database-references/#database-references – WiredPrairie Aug 21 '13 at 21:29
  • Otherwise, I'd just suggest you try creating a script that will treat each bad DBref as just a plain object, and then update it as a DBRef. – WiredPrairie Aug 21 '13 at 21:31
  • Besides, it is a very bad idea to change something as fundamental as a collection name when moving from dev to production. If you really must do it, the order of keys in the document should not be affected by an update with `$set`. You did use `$set`, right? – drmirror Aug 21 '13 at 21:31
  • I used DBRef as it was a first project with mongo and we were trying this option, now I realize that is not quiet the best thing. Will try the script. And yes, I've tried with $set and that only rearranged the order of the DBRef letting the reference USELESS! So, i guess that the best option (past) was not to use DBRef, and now, it will be to create a new functionality. Guess it will be better to clean the DB and code to remove all DBRef :( – user2705160 Sep 10 '13 at 20:37
  • Thank you for the replies, and sorry it took so long for me to comment :) – user2705160 Sep 10 '13 at 20:38

0 Answers0