Loopback-mongodb-connector to support slug identifiers

I want to use slugs ( String) instead ObjectIDfor some of the objects subject to REST in Loopback

What the docs say about model identifiers:

By default, if no ID properties are defined, and the idInjection of model parameters is false, LDL automatically adds the id property to the model as follows:

id: {type: Number, generated: true, id: true}

I thought I just needed to specify Stringboth type and generated: falseto avoid this loopback instead ObjectID.

id: { type: String, generated: false, id: true },

-> It didn't work at all

In the code , mongodb.jsI see that regardless of my name idit is wrapped using a ObjectIDfunction that explains the loss of value String.

: generated mongodb, ?

(objectId, , ) , :

id: {
    type: String, 
    objectId: false, 
    id: true
},

: MongoDB.prototype.create@mongodb.js:155:

var isObjectId = self.getDataSource(model)
                     .getModelDefinition(model)
                     .properties[idName]
                     .objectId;

if (idValue === null) {
    delete data[idName]; // Allow MongoDB to generate the id
} else {
    var oid = isObjectId ? ObjectID(idValue) : idValue; // Is it an Object ID?
    data._id = oid; // Set it to _id
    delete data[idName];
}

save() , / slug REST.

, , - ?

, , , , , StrongLoop , .

+3
1

:

  • id: { type: String, generated: false, id: true }
    

  • ObjectID

    id: { type: String, generated: true, id: true }
    

LoopBack mongodb . ObjectID, ObjectID.

​​, :

https://github.com/strongloop/loopback-connector-mongodb/pull/15

, https://groups.google.com/forum/#!forum/loopbackjs, .

+3

All Articles