node js mongodb remove error "key $lte must not start with '$'" - node.js

db.collection('session').remove({timestamp:{'$lte':a}},function(err, docs) {
console.log(err)
console.log(docs)
});
Version mongodb is 2.6.5, when I make this query from Robomongo visual manager it works normally but from node js it throws error "key $lte must not start with '$'"

I also faced similar issue with some downloaded code- shell worked properly but Node driver failed (there was no other external library like mongoose). My installed MongoDB version was 2.6.6 and the package.json had a mongodb entry as "~1.3.18". With a suggestion from someone, I changed the entry value to "~1.4.31" which resolved my problem.

Remove the quotes around $lte. It is not a key, but a directive.

Related

strapi start: "url is not defined" - using mlab mongo DB

When I run 'strapi start' I get the following output in my terminal:
debug ⛔️ Server wasn't able to start properly.
Error URL is not defined
Any solutions? I have recreated my mlab DB 3 times and when I enter all the values in the terminal to create the new strapi server I double check my values and everything from GitHub issues and strapi documentations say I'm doing the correct thing, but not able to figure out why this is happening! Appreciate any help!
As #soupette have said in the comment:
Strapi needs Node v10 to be installed in order to work. If you upgrade
your node version it should be working properly
I can confirm the same error on my end with NodeJS 8.11.1
Strapi's GitHub page confirms that minimum NodeJS version is 10.x
Ok when you create a Mondo db on mlab you get this information:
mongo ds129484.mlab.com:29484/blog -u <dbuser> -p <dbpassword>
mongodb://<dbuser>:<dbpassword>#ds129484.mlab.com:29484/blog
When you start a strapi project, you make this
strapi new blog
cd blog
strapi start
So you select mondodb how to default db and the cli show the follow questions, and you would be add the following answers, supposing that you have the db data showed before:
DBname: blog
host: ds129484.mlab.com
srv connection: false
port: 29484
username: username created on mlab for your db
password: username password created on mlab for your db
authentication db: blog (you have put the name of your db)
enable ssl: false
You press Enter and you project would be run perfectly
First of all you must have Node 10 or above. If you still getting error edit the following file:
config/host.json
Use an higher timeout value.
{
"timeout": 60000,
......
}
Assuming you are on the correct node version, goto the configuration.js found in node_modules/strapi/lib/core/configurations.js and update lines 331-333.
Replace
this.config.admin.url = this.config.admin.devMode ?
(new URL(adminPath, `http://${this.config.host}:4000`)).toString():
(new URL(adminPath, url)).toString();
With
this.config.admin.url = this.config.admin.devMode ? `http://${this.config.host}:4000/admin`:`http://${this.config.host}:1337/admin`
Thanks
Here is what worked for me:
Just upgrade your node js installation to version 10

Different Insert response from mongodb nodejs native driver on OSX and Windows

I'm getting different responses when inserting documents from Windows and OSX to an external MongoDB database.
Both systems are using mongodb driver v2.1.11 from https://www.npmjs.com/package/mongodb
Inserts are working fine on both but the result I get back is quite different.
OSX: { result: { ok: 1, n: 1, ...other data}, ops: [the inserted records] }
Win: [the inserted records]
Any idea why this is happening?
Steps to reproduce:
nodejs: 5.7.0
npm: 3.6.0
mongodb (from npm): 2.1.11
Given a nodejs application, install v2.1.11 of the official MongoDB driver for nodejs:
npm install --save mongodb#2.1.11.
From your nodejs application, import mongo, create a mongo client and connect to a MongoDB instance and insert a document into a collection:
import mongo from 'mongodb';
const MongoClient = mongo.MongoClient;
MongoClient.connect(mongoUrl, (err, db) => {
db.collection('someCollection').insert({ foo: 'foo'}, (insErr, result) => {
console.log(result); // Observe the result shape is different on Win/OSX
});
});
It turns out there was a package.json buried deep in my application that contains a lower version of the MongoDB driver.
Removing this pacakge.json and ensuring that everything was kept in the top level package.json has solved the problem for me.

MongoDB Error: "key $ne must not start with '$'"

I had hunt with this error: node js mongodb remove error "key $lte must not start with '$'", but that did not helped me.
I am doing following query
coll.remove({ _id : { '$ne' : SomeId }, blah : blaVal });
But that gives the error :
key $ne must not start with '$'
I have started facing this issue, when i migrated mongodb 2.4 to 2.6
My configs are:
nodejs : 0.10
mongodb : 2.6.8 (no issues with 2.4.x)
mongodb driver (npm package version) : 2.1.3 (have tried with 1.4.x and 1.3.x, but error is still there, even emptying node_modules and again `npm install`)
What should I do to resolve the issue?

Node.js and Mongodb

So i am trying to use Node.js and Mongodb together and the goal is to use Node to get information and store it in a database with Mongodb. SO I have both Node and Mongdb intalled, and I install the Mongodb package with npm, this is the package mongodb recommends. But the problem I am having is that when I try to do
MongoClient.connect("mongodb://localhost:3000/exampleDb", function(err, db) {
if(err) { return console.dir(err); }else{
var collection =db.createCollection('test', function(err, collection) {}); }});
and I go to localhost:port_for express_server, but when the above code is supposed to run I get [Error: failed to connect to [localhost:3000]] in the Node console.Am I supposed to be running mongodb in the background or how is this supposed to work?
when you do
npm install mongodb
you only install a node.js client driver for mongodb.
in order for you script to run, you need to install and start a mongodb server on your box
check server installation procedures on http://docs.mongodb.org/manual/installation/
You seem pretty lost on what mongodb is and how to use it. Mongodb is a noSQL database.
Am I supposed to be running mongodb in the background
Yes, like mysql, you need the server to be installed and running, to use it. You need to do:
mongodb (the db server)
install server
start the server by typing mongod on terminal
check with mongo if it is running and you can connect to it.
node.js (the web server)
install node
install mongodb package
now test your code

Nodejs and Sphinx data query issue

I have been using limestone module and Nodejs to query sphinx index. The limestone is out-dated in my npm so i downloaded from github and it is got connected to the sphinx server successfully. But i am now facing the issue as follows,
When i tried to execute the following code,
var limestone = require("limestone").SphinxClient(),
sys = require("sys");
limestone.connect("192.168.2.443:9312", // port. 9312 is standard Sphinx port. also 'host:port' allowed
function(err) {
if (err) {
sys.puts('Connection error: ' + err);
}
sys.puts('Connected, sending query');
limestone.query(
{'query':'raja',maxmatches:1},
function(err, answer) {
if(err){
console.log("Sphinx ERR: "+err);
}else{
console.log(JSON.stringify(answer));
limestone.disconnect();
}
});
});
i got the below error,
Sphinx ERR: Searchd command older than client's version, some options might not workServer issued ERROR: 0bad multi-query count 0 (must be in 1..32 range)
Please help me on this!
Ok, so I installed sphinxseach on Ubuntu, the version in the repository is 0.9.9. I got a similar error as yours:
Searchd command older than client's version, some options might not workServer issued ERROR: Qclient version is higher than daemon version (client is v.1.24, daemon is v.1.22) undefined
After looking through the issues at limestone's github, I figured it was supposed to work with Sphinx version 2. So I installed 2.0.4 from Sphinx download page (they have Ubuntu packages), and it works! So, if it's possible for you to upgrade, that might be a good idea anyway -- and limestone will probably only ever track the latest release.

Resources