-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dealing with MongoDB objectId primary keys? #363
Comments
try this #86 (comment) |
I did try, it didn't not work, at least not in the way I expected it to work. Maybe my expectations are wrong? I expect:
What I get:
This is problematic because
I tried with "_id" and "_id.$oid". I even tried without any configuration at all, the result does not change. I tried the following variants (separately, not together ;-) angular
.module('client')
.factory('Client', Client)
.factory('TestClient', TestClient)
.factory('Clientsearch', Clientsearch)
.factory('Clientcount', Clientcount)
.factory('Clientpaged', Clientpaged)
.config(config);
config.$inject = ['restmodProvider'];
// this is what i used before the backend started throwing ObjectIDs instead of strings
// variant 0 -> $pk = Objectid, _id is empty :-(
function config(restmodProvider) {
restmodProvider.rebase({
$config: {
primaryKey: '_id'
}
});
}
/*
// variant 1 -> $pk = Objectid, _id is empty :-(
function config(restmodProvider) {
restmodProvider.rebase({
$config: {
primaryKey: '_id.$oid'
}
});
}
// variant 2 -> pushModelBase is not a function - has been renamed to rebase
function config(restmodProvider) {
restmodProvider.pushModelBase(function() {
this.setPrimaryKey('_id');
});
}
// variant 2a -> $pk = Objectid, _id is empty :-(
function config(restmodProvider) {
restmodProvider.rebase(function () {
this.setPrimaryKey('_id.$oid');
});
}
// variant 2b -> $pk = Objectid, _id is empty :-(
function config(restmodProvider) {
restmodProvider.rebase(function () {
this.setPrimaryKey('_id');
});
}
// variant 3a -> $pk = Objectid, _id is empty :-(
function config(restmodProvider) {
restmodProvider.rebase({
$config: {
PRIMARY_KEY: '_id'
}
});
}
// variant 3b -> $pk = Objectid, _id is empty :-(
function config(restmodProvider) {
restmodProvider.rebase({
$config: {
PRIMARY_KEY: '_id.$oid'
}
});
}
*/ |
lame, this is also stopping me from using angular-restmod |
Well, it doesn't exactly stop me, it just leads to byzantine code I could do without. Just out of curiosity did anything you tried change anything on the outcome? What puzzles me most, is the fact, that whatever I tried it always turned out exactly the same. |
I opted for js-data-angular |
Hi!
I'm stuck on dealing with primary keys delivered from the mongodb based backend.
The keys look like this:
I have tried various mappings, both global and local as mentioned on various parts of the website, issues, etc. But at best I can set $pk to a copy of _id. Savings fails, because _id is empty on PUT.
Thanks!
The text was updated successfully, but these errors were encountered: