[SERVER-2749] Collection inaccessable via db.foo.find(); if you save {toString : {}} Created: 12/Mar/11  Updated: 12/Jul/16  Resolved: 11/Mar/13

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: 1.6.5
Fix Version/s: 2.4.0-rc2

Type: Bug Priority: Minor - P4
Reporter: Kendrick Taylor Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OSX, MongoDB 1.6.5, although I imagine it's a cross platform bug


Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

Steps to reproduce in the shell:

db.bug.save({toString : {} });
db.bug.find();

Resulting error message: "TypeError: x.toString is not a function"

You don't get any results and the only way to fix it in the shell is either db.bug.remove(); or db.bug.drop();

I know it's a stupid object to save, but a bug in my code saved an object with {toString : {} } and I ran into this.

Throw this in there:

(typeof(x.toString) === 'function') ? x.toString() : x

Thanks.



 Comments   
Comment by Andy Schwerin [ 11/Mar/13 ]

Works at least as of 2.4.0-rc2.

Comment by Scott Hernandez (Inactive) [ 12/Mar/11 ]

I was able to reproduce this on 1.8rc2:

> db.test2.find()
TypeError: x.toString is not a function
> db.test2.find().toArray()
Fri Mar 11 20:05:13 TypeError: x.toString is not a function shell/utils.js:842

Generated at Thu Feb 08 03:01:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.