mongoose更新无法正常工作

时间:2015-05-24 04:38:21

标签: javascript node.js mongodb mongoose

我在stackoverflow上检查了很多问题并修改了这个不起作用的简单查询我不知道为什么......

swapflag = 0
n = gets.to_i
for i in 0..n-1
    tc = gets
    tc2 = gets
    if tc.length > tc2.length
        tmp = tc2
        tc2 = tc
        tc = tmp
        swapflag = 1
    end

    tc.delete! " "
    tc2.delete! " "

    tc.split("").each do |x|
        if tc2.include? x
            #print x
            tc = tc.sub(x,'')
            tc2 = tc2.sub(x,'')
        end
    end
    #puts tc, tc2
    if tc.length > 0 and tc2.length == 0 and swapflag == 0
        puts "You win some."
    elsif tc.length > 0 and tc2.length == 0 and swapflag == 1
        puts "You lose some."
    elsif tc.length == 0 and tc2.length > 0 and swapflag == 0
        puts "You lose some."
    elsif tc.length == 0 and tc2.length > 0 and swapflag == 1
        puts "You win some."
    else
        puts "You draw some."
    end

    swapflag = 0
end

我尝试过很多方法,例如使用带有upsert true和false的model.update .... 另外它的console.log在回调中给出了正确的用户名....但是数据库没有变化...

2 个答案:

答案 0 :(得分:0)

如果您在.save之前使用3.x版本的mongoose可用于更新模型,则需要在模型上将该字段标记为已修改。

#this work

json.number @category.posts.count

#this one doesn't work

json.number @category.posts.comments.count

答案 1 :(得分:0)

要尝试的另一件事是

user.set('suspended', true);