MongoDB + Nodejs insert maximum length - node.js

I'm trying to insert a large amount of text into a mongodb collection from nodejs. I've done some testing and found that the maximum length of the string can be only 49072. Here's how i do it:
collection.insert({'largetext':POST["text"]});
Basically if I do a substring of (0, 49072) it works fine. (I can see the collection in mongodb). But if i do (0, 49073) then it just never appears in the db. There is no error either (I tried using {safe:true}, and using an error function to capture any errors...there weren't any).
I'm using http://github.com/christkv/node-mongodb-native/ as my mongo driver.
Anyone have any clues what could be wrong here? I think it might be some Javascript maximum string length restriction, but if it is how do i still insert large text?
Thanks!

I've got a test in master that inserts a 50000 character string
https://github.com/christkv/node-mongodb-native/blob/master/test/insert_test.js#L1180
passes without any problems so this might be a red herring and the problem could be somewhere else. I would suggest you try the test and see if it passes. also make sure you are on the latest node.js version and latest npm package.

Related

Discord.js message includes

Hi im currently adding some new features to a bot and it's been going great with some amazing progressions each day. I ran into an issue that i can't seem to solve even though i feel like the solution is right in front of me. In my code i have an if statement to check if a user has more matches won than 22 in the database, if so they are allowed to equip a certain background if not it returns an error message. I tried to do another if statement to check if a certain user is trying to run the command by matching their discord ID and for some reason it runs both the if statements when doing either command even though i used message.content.includes to specify what arguments it should look for in the command. Any help would be appreciated
According to the mozilla docs:
The comma operator (,) evaluates each of its operands (from left to right) and returns the value of the last operand.
This means that only the second operand in each if statement is being returned, ignoring message.content.includes().
Changing the , to && should fix the issue.
source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator

Checking document count in PyMongo.cursor.Cursor inside if statement in python behaving wierdly

I have the following python code:
placeholder = db.user.aggregate(...)
if len(list(placeholder))!=0:
#execute something
Now the issue is even if the mongo cursor doesn't have any documents, it still getting inside the if statement.
But if I am modifying the code as:
placeholder = list(db.user.aggregate(...))
if len(placeholder)!=0:
#execute something
its working normally.
even if pymongo cursor object is an iterator and it can be exhausted but the only thing I am doing is checking the length and converting it into a list. Can anyone please advice why its behaving this way in the first case.
Thanks in advance.
As long as the query is the same, the two statements are identical.
In the first query - how do you know there's no records. You exhaust the cursor without saving any results to look at. Also how is it possible that "the mongo cursor doesn't have any documents", while len(list(cursor)) returns a non-zero value.
If you are really stuck, post a Minimal Reproducible Example.

Node.js wrong UTF8 string representation, even though byte-codes seem correct

Having searched around for a while now, I believe my problem may not be directly related to what others had. I am using unicode chars in forms (using angularjs for client-side) and noticed that the UTF8 strings didn't display on the server logs properly. Thus I decided to base64.encode all strings on the client side before submitting to the server (nodejs/express4). The JSON data arrives properly to the server, but when I try to convert it from base64 to UTF8 using a buffer I'm getting different symbols. I tested the strings on http://www.base64decode.org/ and they decode fine. Can anyone suggest what I might be doing wrong?
Example char: σ, base64="z4M=".
On the server this line decodes all JSON values to UTF8:
Object.keys(req.body).forEach(function(key) { req.body[key] = new Buffer(req.body[key], 'base64').toString('utf8'); });
And the "σ" char becomes "Ο" on the server. Anyone can assist?
Thus I decided to base64.encode all strings on the client side before submitting to the server (nodejs/express4).
No need to, really. Probably the thing you were doing wrong with utf-8 json is also wrong now.
Try to debug that.
noticed that the UTF8 strings didn't display on the server logs properly.
What do they display?
And on what OS are you?
Did you look at the logs with a hex viewer?
To me this looks like a typical "I have an a problem X, thought my solution half the way, but I am stuck with a sub-problem Y". Go back to X and attack it the right way (no base64).

Neo4j - index lookup issue

I was trying to set index type from exact to fulltext in neo4j shell, so i can do incasesensitive search with lucene query. So i used this command:
index --set-config Destination type fulltext
but it didn't work. Still couldn't do case insensitive search, so a played around and change some other values, like _blueprints:type and to_lower_case.
That didn't do any good.
Now it somehow ignores first character of name value ( weird ! ) . So if i am searching for "London" for example and i type "Lon" it returns nothing. But if i type "ond" it returns the node. The same for every node.
I tried setting everything back to normal. Didn`t help.
What did i mess up? What am i missing?
I am using a Everyman PHP library to communicate with database.
I created new index with "to_lower_case" property.
I think that will solve my problem, just have to convert string to lower case before inserting it into query. It seems to work.
Setting configuration afterwards doesn't update already indexed values (as the shell notes, I think). If you've created your index with "to_lower_case=true" then additions as well as queries will have the values converted to lower case. Calling Index#get will still require you to lower-case it yourself.

Solr sort by min of two fields?

I want to sort a result set by the minimum of several fields.
So after reading the functionquery documentation this is what I came up with:
sort={!func}min(dvd_available_from_tdt,dto_available_from_tdt)%20desc
I also tried:
sort=_val_:min(dvd_available_from_tdt,dto_available_from_tdt)%20desc
sort=_val_:"min(dvd_available_from_tdt,dto_available_from_tdt)"%20desc
sort=_val_:"min(dvd_available_from_tdt,dto_available_from_tdt)%20desc"
sort="{!func}min(dvd_available_from_tdt,dto_available_from_tdt)"%20desc
sort={!func}min(dvd_available_from_tdt,dto_available_from_tdt)%20desc
sort="min(dvd_available_from_tdt,dto_available_from_tdt)"%20desc
and also some other placements of the quotes. But no matter what I always get this error:
HTTP ERROR: 400
Missing sort order.
Can anyobody point me in the right direction?
Try using a query that matches all documents, with a constant score, plus a function.
http://localhost:8983/solr/select/?q=%3A+_val_:price&version=2.2&start=0&rows=10&indent=on&debugQuery=true
Also, upgrading to Solr 3.3 is not that painful, and there's all sorts of cool new toys like sorting by function.
It seems to be available only in solr 3.1. I am running 1.4.1
http://wiki.apache.org/solr/FunctionQuery#Sort_By_Function

Resources