Giter Club home page Giter Club logo

Comments (7)

joshuajabbour avatar joshuajabbour commented on June 9, 2024 3

Yes, we can check for the index, and I do think we should throw if there isn't one. Adding the index should be required, otherwise it's not actually an id field. I'll put together a PR.

from feathers-mongodb.

daffl avatar daffl commented on June 9, 2024 1

I was just replying and then @marshallswain beat me to it.

We changed the adapters from doing all the connection and collection setup stuff themselves to just passing the initialized collection. I agree that it makes sense to have the user do it but we should mention it in the docs. Is there maybe also a way to check if there is a unique index on the passed id field and throw a warning?

from feathers-mongodb.

marshallswain avatar marshallswain commented on June 9, 2024

I don't think the adapter should create indexes or unique rules, but it would be nice of us to mention how to do it in the docs.

from feathers-mongodb.

joshuajabbour avatar joshuajabbour commented on June 9, 2024

So this becomes really difficult due to the trickery that's demonstrated in the tests. Specifically, initializing a service without a Model and later adding it like app.service('people').Model = db.collection('people'). If this is a common pattern, there's no way to validate the proper index.

My current plan is to validate that Model is a Mongo collection in the constructor, and if so run the index check. If not, there's not much we can do. Not as safe as I'd like, but I guess if users are initializing services without a db, then there's not much to be done.

from feathers-mongodb.

daffl avatar daffl commented on June 9, 2024

It's really just a workaround for the asynchronous initialization of the plugin (which you correctly pointed out we should solve properly). Could we add a verifyIndices method that can be called manually but also runs in the constructor (if this.Model is set)?

from feathers-mongodb.

joshuajabbour avatar joshuajabbour commented on June 9, 2024

Yeah, that's basically the route I've taken. If Model exists, then we check it for the proper index. If not, it's up to the user. I'll update the docs to clarify how this works, and that the index is required for the id field to work properly.

from feathers-mongodb.

daffl avatar daffl commented on June 9, 2024

I just merged #62 which doesn't have the weird workaround for setting the model. Are we still going to add the index check?

from feathers-mongodb.

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.