Loopback MongoDB String Property converted to ObjectId when using Where Where clause

I have a model with a number of properties. One of them is a field called "developerId" that contains a string that has the same length and characteristics as the MongoDB ObjectId (actually a gated ObjectId).

When I request a model with the find () method in Node.js, the request is updated before it is executed, and the value "DeveloperId" is converted to ObjectId, which then cannot match any rows in the database, these are strings, not ObjectIds.

{where: {developerId: '55118c5fc921fa170f05080b'}} 

Converted to:

 {where: {developerId: ObjectId('55118c5fc921fa170f05080b')}} 

The field is not an id field; it is set as type: 'string' in the json model definition.

How to disable this auto-object-id object behavior so that I have control over Loopback requests?

+7
mongodb loopbackjs
source share
2 answers

Looks like you found a bug / lack of framework. See here:

https://github.com/strongloop/loopback-connector-mongodb/issues/52

The error, apparently, has not yet been resolved as of two months ago. Welcome to the wild west, which may be a node.

In the short term, you can fork out and hack the module while working with the community to solve this problem.

You can also try using the basic mongo connection to execute the request and then map it back to loopback objects. You can get it like this:

 app.models.User.dataSource.connector 

I assume that you can always change the developmentId field of your model as the actual ObjectId.

+4
source share

make sure that in your Json file properties the developer is defined as a Sample object:

 "Properties" { ... "developerId": { "type": { "required": true } } ... } 
0
source share

All Articles