Coder Social home page Coder Social logo

How to do a populate? about mongoose-sequence HOT 2 CLOSED

ramiel avatar ramiel commented on May 14, 2024
How to do a populate?

from mongoose-sequence.

Comments (2)

ramiel avatar ramiel commented on May 14, 2024

Hello. So, a couple of things here: populate works only with _id and not with id, like you're trying to do here. Also, populate should work only with objectID and not with other types.

From a larger point of view I'd suggest,in general, not to try to replace the _id of mongo collection with something else. If you need an incremental index for a collection use another field (be aware that, for mongoose, id is an alias for _id unless you specify differently). The reason is that the _id as an ObjectId is a so deep concept for mongo that trying to replace it can easily lead to issues. Also many other libraries out there rely on this concept.

The idea of having an incremental property in your model, which is also indexed, can be handy in certain situations, in fact I created this library but most of the time is just a residual of many years used to relational databases. After all it is worth remembering that ObjectIds are orderable without any new paradigm: any new objectId come before the older, when sorting descending.

from mongoose-sequence.

idzer0lis avatar idzer0lis commented on May 14, 2024

Hello. So, a couple of things here: populate works only with _id and not with id, like you're trying to do here. Also, populate should work only with objectID and not with other types.

From a larger point of view I'd suggest,in general, not to try to replace the _id of mongo collection with something else. If you need an incremental index for a collection use another field (be aware that, for mongoose, id is an alias for _id unless you specify differently). The reason is that the _id as an ObjectId is a so deep concept for mongo that trying to replace it can easily lead to issues. Also many other libraries out there rely on this concept.

The idea of having an incremental property in your model, which is also indexed, can be handy in certain situations, in fact I created this library but most of the time is just a residual of many years used to relational databases. After all it is worth remembering that ObjectIds are orderable without any new paradigm: any new objectId come before the older, when sorting descending.

Many thanks for the detailed explanation.

I wish you a great day and thanks for the library!
Cheers

from mongoose-sequence.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.