These are chat archives for Automattic/mongoose

18th
Aug 2016
temuccio
@temuccio
Aug 18 2016 07:01
Hello all... I have one problem with mongoose query
I can't find all record with number type equal 0
I execute this query:
database.Order.find({stato: 0},function(err,succ){
but doesn't find in database
the database has record with stato = 0
{
    "_id" : ObjectId("57b55c890046840006301b34"),
    "idutente" : "57ab4a9a1cad28c114fe879b",
    "datacreazione" : ISODate("2016-08-18T06:58:17.232Z"),
    "stato" : "0",
    "totalecosto" : 0.04
}
{
    "_id" : ObjectId("57b55ca1b496ab1806a8a9df"),
    "idutente" : "57ab4a9a1cad28c114fe879b",
    "datacreazione" : ISODate("2016-08-18T06:58:41.458Z"),
    "stato" : "0",
    "totalecosto" : 0.04
}
{
    "_id" : ObjectId("57b55cb80f4fb72406bf9751"),
    "idutente" : "57ab4a9a1cad28c114fe879b",
    "datacreazione" : ISODate("2016-08-18T06:59:04.047Z"),
    "stato" : "0",
    "totalecosto" : 0.04
}
How I cand find with stato?
Vlado Tesanovic
@vladotesanovic
Aug 18 2016 07:13
@temuccio database.Order.find({stato: "0"}
your stato is string
temuccio
@temuccio
Aug 18 2016 07:13
in schema stato is defined as number
    var orderSchema = new mongoose.Schema({
        numeroordine: {type: Number}, 
        idutente: {type: String},
        idcopisteria: {type: String},
        datacreazione: {type: Date, default: Date.now, select:false},
        datainviocopisteria: {type: Date, default: Date.now, select:false},
        datastampa: {type: Date, default: Date.now, select:false},
        dataconsegna: {type: Date, default: Date.now, select:false},
        stato: {type: Number},
        totalecosto: {type: Number}, 
        tipo: {type: Number}, 
        corriere: {type: Boolean, default: false},
        ntracking: {type: String} 
    });
but if I query with {stato: "0"} doesn't work
Vlado Tesanovic
@vladotesanovic
Aug 18 2016 07:20
{stato: {'$eq': 0}}
temuccio
@temuccio
Aug 18 2016 07:22
@vladotesanovic I have try {stato:{'$eq':0}} and {stato:{'$eq':'0'}} but doesn't work :worried:
Vlado Tesanovic
@vladotesanovic
Aug 18 2016 07:22
@temuccio why you use database.Order ?
what empty find({}) returns?
temuccio
@temuccio
Aug 18 2016 07:23
@vladotesanovic because the schema is defined in database.js file as modules.export.
If I execute empty find({}), they return this:
[ { _id: 57b477b4a0465ff3127eb684,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b477e6a0465ff3127eb686,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 49.02,
    corriere: false },
  { _id: 57b557e75c2739f3044d17f7,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b55807abcbd50805d3a10d,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b5581ae795991705f3d0c3,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b55834c7b7e923053642b6,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b55b8cafdbd392054ff13c,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b55b9d36901aa305b4516e,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b55bf70ab82fb805448be4,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b55c0681c2e2c405298506,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b55c3707a613d405c91abc,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b55c68cf94c1f2059ab049,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b55c890046840006301b34,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b55ca1b496ab1806a8a9df,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b55cb80f4fb72406bf9751,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b560e932d52827070c5da4,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b561dd3aaba27a07d4239b,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b561f185fb268b07c58201,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false },
  { _id: 57b5624085d423b90760cf86,
    idutente: '57ab4a9a1cad28c114fe879b',
    stato: 0,
    totalecosto: 0.04,
    corriere: false } ]
I don't understand why query with stato doen't work
Vlado Tesanovic
@vladotesanovic
Aug 18 2016 07:29
neither I, look very weird
temuccio
@temuccio
Aug 18 2016 07:31
in mongo client, this db.ordini.find({'stato':{'$eq':'0'}}).pretty() and this db.ordini.find({'stato':'0'}).pretty() works fine
grrr
Vlado Tesanovic
@vladotesanovic
Aug 18 2016 07:33
@temuccio yea they should
temuccio
@temuccio
Aug 18 2016 07:38
OK @vladotesanovic , in the schema, if I change number as string, the query works with mongoose
Why?
ok I find the problem...when I insert stato, i haved this string: stato:'0' and this is a string but not a number; if i insert stato:0 it's works fine....Thanks @vladotesanovic
Vlado Tesanovic
@vladotesanovic
Aug 18 2016 07:41
@temuccio yep, cool :+1:
zeeshanhameednxb
@zeeshanhameednxb
Aug 18 2016 12:27
Hi! I'm new in mongodb. I want _id as integer (1,2,3) instead of 16 digit
Vlado Tesanovic
@vladotesanovic
Aug 18 2016 12:33
@zeeshanhameednxb just save it as integer, no problem with that