Git Product home page Git Product logo

Comments (9)

cginzel avatar cginzel commented on May 11, 2024

based on what you have above and especially given your solution, wouldn't it be more correct to say your findByPermalink(permalink).first is the suspect? a find should not return isNew = true. and if i update the model.test.js to add isNew assertion test cases after a find, they all pass (http://github.com/cginzel/mongoose/blob/faabdc1a55f9bb9716f750bb3be72187ce61d193/tests/integration/model.test.js) where is the code for findByPermalink(permalink).first?

from mongoose.

xdamman avatar xdamman commented on May 11, 2024

I've just added findByPermalink in the static methods of the model.

    mongoose.model('Story',{
        
        collection  : 'stories',
        'static'    : {
            
            findByUserid    : function(userid) {
                return this.find({'user.id':userid,'deleted':null});
            },
            
            findByUsername  : function(username) {
                return this.find({'user.username':username,'deleted':null});
            },
            
            findByPermalink : function(permalink) {
                return this.find({'permalink':permalink,'deleted':null});
            },

from mongoose.

cginzel avatar cginzel commented on May 11, 2024

do the test cases in my link above pass when you run it in your environment?

from mongoose.

xdamman avatar xdamman commented on May 11, 2024

All tests are ok.
Weird. I've moved on doing soft delete (with a delete flag) so I won't have to delete anything from mongodb. Let's see how it goes.

from mongoose.

xdamman avatar xdamman commented on May 11, 2024

Thanks for your support btw!

from mongoose.

cginzel avatar cginzel commented on May 11, 2024

are you sure the your query actually returns rows? this.find({'permalink':permalink,'deleted':null}); i was convinced at one point the delete did not work too, but i finally figured out that it was my query that was not right.

from mongoose.

batasrki avatar batasrki commented on May 11, 2024

@xdamman,

I thought exactly what you did there. This works instead:
R.remove({'permalink':permalink,'deleted':null}, function() { // where R is the model name of r
//your callback functionality here
})

from mongoose.

batasrki avatar batasrki commented on May 11, 2024

Just to add, there are two remove() functions inside Mongoose. One is the one you pointed above, the other one is a "class" one that takes a where query and the callback function. The second one works perfectly.

from mongoose.

nw avatar nw commented on May 11, 2024

resolved

from mongoose.

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.