Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"name":"MongoError","ok":0,"errmsg":"can't find ns" #2313

Closed
xiaojunl opened this issue Sep 19, 2014 · 10 comments
Closed

"name":"MongoError","ok":0,"errmsg":"can't find ns" #2313

xiaojunl opened this issue Sep 19, 2014 · 10 comments
Milestone

Comments

@xiaojunl
Copy link

Upgrade from version v3.8.8 to v3.8.16,invoke getNear.

@vkarpov15
Copy link
Collaborator

Hi @xiaojunl , can you provide me some standalone code that reproduces this?

@xiaojunl
Copy link
Author

ShopModel.geoNear([121.600590,31.198366], {geoNear: 'name', spherical: true, distanceMultiplier: 6371, num: 100, maxDistance: 20 / 6371, query: {'traffic.status': 'on', name: {$regex: word}}}, function (err, shops, stats) { ... }

@vkarpov15 vkarpov15 added this to the 3.8.18 milestone Sep 26, 2014
@vkarpov15
Copy link
Collaborator

Thanks for that. This will go faster if you provide one standalone file that reproduces this that includes schema definitions though :)

@xiaojunl
Copy link
Author

Of course :)
var shopSchema = new Schema({
name: String,
imgUrl: String, // icon
traffic: {
status: String,
beginTime: String,
endTime: String
},
delivery: {
status: String,
beginTime: String,
endTime: String,
basePrice: Number,
maxRadius: Number,
isCity: String
},
address: {
loc: {type: [Number], index: '2dsphere', sparse: true},
full: String
},
_shopCate: {type: Number, ref: 'ShopCate'},
_parentId: { type: Number, ref: 'Shop' },
vet: {
status: Number, // ∈{0,1,2}
reason: String
},
area: Number,
type: Number,
deleteFlg:Number,
level: Number,
createTime: Number,
modifyTime: Number
});

@vkarpov15 vkarpov15 modified the milestones: 3.8.19, 3.8.18 Oct 22, 2014
@327
Copy link

327 commented Nov 6, 2014

@vkarpov15
hello,
do you have any solution for the "can't find ns"?

@vkarpov15
Copy link
Collaborator

@327 this is caused by you putting that geoNear option. That's for some reason overwriting the namespace used for the underlying geoNear command (that's a bug).

Replace:

ShopModel.geoNear(
  [121.600590,31.198366],
  {
    geoNear: 'name', // <--- This is the bad option
    spherical: true,
    distanceMultiplier: 6371,
    num: 100,
    maxDistance: 20 / 6371,
    query: {'traffic.status': 'on', name: {$regex: word}}},
    function (err, shops, stats) { ... });

With:

ShopModel.geoNear(
  [121.600590,31.198366],
  {
    spherical: true,
    distanceMultiplier: 6371,
    num: 100,
    maxDistance: 20 / 6371,
    query: {'traffic.status': 'on', name: {$regex: word}}},
    function (err, shops, stats) { ... });

And you should stop getting that error.

@vkarpov15
Copy link
Collaborator

Further clarification: specifying 'name' is not necessary there - since there can only be one 2d index on an object, there's no need to tell geoNear which field to use

@327
Copy link

327 commented Nov 9, 2014

@vkarpov15 thank you very much !
These code in my project is worked well:

$mongo = new MongoClient("mongodb://admin:[email protected]");
$d = $mongo->selectDB('Ituji');
$d->selectCollection('UserInfo')->ensureIndex(array('loc' => '2dsphere'));
$query = array(
    'geoNear' => "UserInfo",
    "distanceField" => "dist.calculated",
    "near" => array("type" => "Point", "coordinates" => [$lng, $lat]),
    "spherical" => true,
    "num" => $num);
$result = $d->command($query);

hope it's useful for other people

@xiaojunl
Copy link
Author

right,resolved.

@sumerpatel7
Copy link

{ $geoNear: { near: { type: "Point", coordinates: [parseFloat(user_result.lng), parseFloat(user_result.lat)] }, distanceMultiplier: 0.001, maxDistance: 100000, spherical: true, distanceField: "dist.calculated", query: { lat: { $ne: '' }, lng: { $ne: '' } } } }

This will solve your problem with ns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants