Giter Club home page Giter Club logo

Comments (6)

jedireza avatar jedireza commented on May 18, 2024

Thanks for opening an issue. Do you mean it should return an array or that it does and the docs are wrong?

from hapi-mongo-models.

Miscellaneous avatar Miscellaneous commented on May 18, 2024

I would imagine, .insertOne() would return an object (without an nesting array).

I get:
result = [ {foo:1} ]

expected:
result = {foo:1}

I base this upon .findOne() or .findById() does indeed only return an object (without the nesting array).

from hapi-mongo-models.

jedireza avatar jedireza commented on May 18, 2024

Ah yes, I remember this. We're simply proxying the call to the driver's insertOne method:

collection.insertOne.apply(collection, args);

According to the docs:
http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#insertOne

insertOne has a writeOpCallback callback:
http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~writeOpCallback

Which defines the result as a WriteOpResult
http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~WriteOpResult

If we chose to change this, it would be a major version bump as the API would change. Is it really worth it?

from hapi-mongo-models.

Miscellaneous avatar Miscellaneous commented on May 18, 2024

I'm new to Mongo, so not really in any position to advise on what is worth it.

I just believed to have discovered an Inconsistency error, but being an artifact from the driver, it might be outside your domain.

Appreciate your framework and your kind support, I hope its not to much trouble too ask.

from hapi-mongo-models.

jedireza avatar jedireza commented on May 18, 2024

I just believed to have discovered an Inconsistency error, but being an artifact from the driver, it might be outside your domain.

We could change it in this library, but I prefer to do as little as possible in that regard.

Appreciate your framework and your kind support, I hope its not to much trouble too ask.

That's always nice to hear. Thanks :) Always feel free to ask questions.

from hapi-mongo-models.

Miscellaneous avatar Miscellaneous commented on May 18, 2024

Model.insertOne() - Workaround to output an object, instead of array with an object

                        Model.insertOne( schema, function( err, model ){
                            if( err ) return reply( err );
                            return reply( model.shift() );
                        });

from hapi-mongo-models.

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.