Argument must be a string in nodejs

KVISH

I'm having the following code:

              var objectid = infos[i].id;
              var name = infos[i].name;
              return collection.aggregate([
                {$match: {app: new ObjectId(objectid)}},
                {$group: {_id: "$uid", amt: {$sum: 1}}}
              ])

Previously this code was working fine, but recently I started getting the below stacktrace in sails:

error: TypeError: Argument must be a string
    at TypeError (native)
    at Buffer.write (buffer.js:791:21)
    at serializeObjectId (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:242:10)
    at serializeInto (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:699:17)
    at serializeObject (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:280:18)
    at serializeInto (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:705:17)
    at serializeObject (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:280:18)
    at serializeInto (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:551:17)
    at serializeObject (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:280:18)
    at serializeInto (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:705:17)
    at serialize (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/bson.js:47:27)

It's complaining because of the ObjectId which I imported like so:

var ObjectId = require('mongodb').ObjectID;

As I said before, this was working fine but not anymore. I'm really confused. If I put objectId as a string it will not return any results. If I leave it as is (as it was working before) it throws exceptions. What is the issue here?

I have read the below :

https://docs.mongodb.com/v3.0/reference/operator/aggregation/cmp/#exp._S_cmp

I'm able to do this in robomongo:

 db.getCollection("openevent").aggregate([
                {$match: {app: new ObjectId(OBJECT_ID) }},
                {$group: {_id: "$uid", amt: {$sum: 1}}}
              ])

Using the same values as above. What am I doing wrong??

I see the following for sails-mongo:

└─┬ [email protected]
  └─┬ [email protected]
    └── [email protected]
vkarpov15

For posterity's sake, this is usually due to compatibility issues between versions of mongo. MongoDB driver 2.2 uses mongodb-core 2.0 (and bson 0.5) whereas MongoDB driver 2.1 uses mongodb-core 1.3 and bson 0.4. If you try to use a MongoDB driver 2.1 ObjectId with MongoDB driver 2.2 you'll get this error.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Nodejs: path must be a string

From Dev

int() argument must be a string or a number

From Dev

int() argument must be a string or a number, not 'SimpleLazyObject'

From Dev

unicode() argument 2 must be string not None

From Dev

TypeError: float() argument must be a string or a number, not 'Tensor'

From Dev

int() argument must be a string or a number, not 'SimpleLazyObject' in django

From Dev

Argument 1 must be string, not datetime.datetime?

From Dev

MongoDB: first argument must be string or Buffer?

From Dev

TypeError: float() argument must be a string or a number, not 'IntVar'

From Dev

Argument must be String in django rest framework?

From Dev

Nodejs:Path must be a string without null bytes

From Dev

Nodejs:Path must be a string without null bytes

From Dev

Argument 2 passed to array_sort() must be callable, string given

From Dev

Django TypeError int() argument must be a string or a number, not 'QueryDict'

From Dev

`_pickle.UnpicklingError: the STRING opcode argument must be quoted`

From Dev

Getting TypeError: type() argument 1 must be string, not None

From Dev

R textConnection: "argument 'object' must deparse to a single character string"

From Dev

saving datetimefiled in django models, int() argument must be a string or a number

From Dev

println! error: expected a literal / format argument must be a string literal

From Dev

TypeError: float() argument must be a string or a number in Django distance

From Dev

Argument passed in must be a string of 24 hex characters - I think it is

From Dev

TypeError: int() argument must be a string or a number, not 'datetime.datetime'

From Dev

Django Error: TypeError: int() argument must be a string or a number, not 'BuildsTable'

From Dev

TypeError: int() argument must be a string or a number, not 'Model Instance'

From Dev

int() argument must be a string or a number, not 'builtin_function_or_method' - python

From Dev

throw message; TypeError: first argument must be a string or Buffer

From Dev

Typescript - An index expression argument must be of type 'string', 'number', 'symbol' or 'any'

From Dev

TypeError: Float() argument must be a string or a number when reading a list()

From Dev

When assigning attributes, you must pass a hash as an argument, String passed

Related Related

  1. 1

    Nodejs: path must be a string

  2. 2

    int() argument must be a string or a number

  3. 3

    int() argument must be a string or a number, not 'SimpleLazyObject'

  4. 4

    unicode() argument 2 must be string not None

  5. 5

    TypeError: float() argument must be a string or a number, not 'Tensor'

  6. 6

    int() argument must be a string or a number, not 'SimpleLazyObject' in django

  7. 7

    Argument 1 must be string, not datetime.datetime?

  8. 8

    MongoDB: first argument must be string or Buffer?

  9. 9

    TypeError: float() argument must be a string or a number, not 'IntVar'

  10. 10

    Argument must be String in django rest framework?

  11. 11

    Nodejs:Path must be a string without null bytes

  12. 12

    Nodejs:Path must be a string without null bytes

  13. 13

    Argument 2 passed to array_sort() must be callable, string given

  14. 14

    Django TypeError int() argument must be a string or a number, not 'QueryDict'

  15. 15

    `_pickle.UnpicklingError: the STRING opcode argument must be quoted`

  16. 16

    Getting TypeError: type() argument 1 must be string, not None

  17. 17

    R textConnection: "argument 'object' must deparse to a single character string"

  18. 18

    saving datetimefiled in django models, int() argument must be a string or a number

  19. 19

    println! error: expected a literal / format argument must be a string literal

  20. 20

    TypeError: float() argument must be a string or a number in Django distance

  21. 21

    Argument passed in must be a string of 24 hex characters - I think it is

  22. 22

    TypeError: int() argument must be a string or a number, not 'datetime.datetime'

  23. 23

    Django Error: TypeError: int() argument must be a string or a number, not 'BuildsTable'

  24. 24

    TypeError: int() argument must be a string or a number, not 'Model Instance'

  25. 25

    int() argument must be a string or a number, not 'builtin_function_or_method' - python

  26. 26

    throw message; TypeError: first argument must be a string or Buffer

  27. 27

    Typescript - An index expression argument must be of type 'string', 'number', 'symbol' or 'any'

  28. 28

    TypeError: Float() argument must be a string or a number when reading a list()

  29. 29

    When assigning attributes, you must pass a hash as an argument, String passed

HotTag

Archive