Is it possible to access m.mtime or m.ctime from share.js in derby.js? - derbyjs

I notice that (I think) share.js creates a sub-document called m that contains mtime and ctime in my database. Is there a derby.js way to $orderby based on those attributes?
Thanks

I`m not sure, but you can try something like this:
model.query('collectionName', {$orderby: {_m: {mtime: 1}}});
But anyway _m, _v, _type fields will be removed before you get document from model.

Related

How i can insert local document in my collection?

I wish I could add a document with its contents in my collection but I can not find the line I need to write.
I guess it looks like that but I can not find it.
db.documents.insert( ... )
Yes it does look like that:
db.collection.insert(<document or array of documents>)

jessenger mongodb case insensitive query search

I have 1 issue with mongodb query search with exact values. i want to get collections irrespective of case sensitive. for this i found some querys like below. its working fine.
db.applications.find({"blocks.HOSPITAL_INFO.data.name": new RegExp('^VIKRAM$', 'i')});
in laravel i am using jessengers. . above query i can write as raw query in laravel.
but my issue is when ever i am using $In:{'a','b'} like this how can i write regex for this. FYI 'a','b' are dynamic array values. so how can i write regex for these array values?
The query in MongoDB would be something like this:
db.applications.find({"blocks.HOSPITAL_INFO.data.name":
{$in:[new RegExp('^a$', 'i'),new RegExp('^b$', 'i')]}});
OR, alternatively:
db.applications.find({"blocks.HOSPITAL_INFO.data.name":
{$in:[/^a$/i,/^b$/i]}});
...where a & b are your dynamic variables.
I'm not very familiar with Laravel, but I'm guessing it would look something like this:
$applications = Application::whereIn('blocks.HOSPITAL_INFO.data.name',
[new MongoRegex('^a$/i'), new MongoRegex('^b$/i')])->get();

MongoDB Set Field with Wildcards

I'm wondering if it's possible to have a wildcard in the middle of the field hierarchy for $set
currently I'm using:
db.collection.update({name: /^test$/i}, {$set:{"stats.Human.BattackPlvl": 4}});
I'm curious if i can do something like this:
db.collection.update({name: /^test$/i}, {$set:{"stats.*.BattackPlvl": 4}});
given how "human" can be anything else for each different documents
Thanks in advance

Mongoid, find object by searching by part of the Id?

I want to be able to search for my objects by searching for the last 4 characters of the id. How can I do that?
Book.where(_id: params[:q])
Where the param would be something like a3f4, and in this case the actual id for the object that I want to be found would be:
bc313c1f5053b66121a8a3f4
Notice the last for characters are what we searched for. How can I search for just "part" of my objects id? instead of having my user search manually by typing in the entire id?
I found in MongoDB's help docs, that I can provide a regex:
db.x.find({someId : {$regex : "123\\[456\\]"}}) // use "\\" to escape
Is there a way for me to search using the regular mongo ruby driver and not using Mongoid?
Usually, in Mongoid you can search with a regexp like you normally would with a string in your call to where() ie:
Book.where(:title => /^Alice/) # returns all books with titles starting with 'Alice'
However this doesn't work in your case, because the _id field is not stored as a string, but as an ObjectID. However, you could add (and index) a field on your models which could provide this functionality for you, which you can populate in an after_create callback.
<shameless_plug>
Alternatively, if you're just looking for a shorter solution to the default Mongoid IDs, I could suggest something like mongoid_token which makes it pretty easy to add shorter tokens/ids to your Mongoid documents.
</shameless_plug>

How to get whole index in ZEND Lucene?

Hi I am looking for a way to get the whole index if my query is nothing.
My lucene is a picture of my database without some unwanted content, like expired annonces...
So I would like to use only lucene to get annonces, and for that I need a way to get the whole index.
Any ideas?
thanks!
This is not the answer but something wich works for me:
Using an indexKey like is_indexed, always true.
I am adding "is_indexed:1" to my query and it works...
If you have something else, let me know!
I tend to use a field which is named after the index such as:
$oDoc->addField(
Zend_Search_Lucene_Field::keyword(
'index',
'availability'
)
);
Then the term query will return all fields. It's not pretty but it works fine.