I want to do a solr search to see if a dynamic field exists or not - search

I want to do a solr search to see if a dynamic field exists or not.
Example:
Doc 1 {
Id: 111
Name: good
Tag_100_is: lsdkl
}
Doc 1 {
Id: 2
Name: not good
}
I want a query to retrieve doc 1.
Thank you in advance.

To query for whether a field exists or not, use field:[* TO *]. So in this case, you should get the document you want by using the query Tag_100_is:[* TO *].
If you want to get the document without the field, you'll have to invert the query (we start with : which are "all documents", then remove the documents that have the field):
q=*:* -Tag_100_is:[* TO *]

Related

How to query field exist some document in firebase

I using firebase, nodejs and i have a question how to query field exist some document.
Example :
Collections : users => document : A with field {
....
is_correct: true
}
document : B with field {
.....
}
In my above example , i have two document in collection users. On document A i have field is_correct: true and on document B field is_correct not exist.
My collection users about 15.000 document and it have 50 document contain field is_correct: true
When i write code look like :
await firestore.collection('users').where('is_correct', '==', true).get();
it can get correct me 50 document. But i don't understand it can using index on field is_correct or not ? And it can query best performance ? I understand firebase can't get document if field undefined. It impart in case ? Please help ? Thanks you
For a simple query like
firestore.collection('users').where('is_correct', '==', true)
you don't need to configure any index, Firestore does it automatically.
As you mentioned, only documents where the given field exists can match the query.
And this is the case also for Not-equal (!=) and not-in queries: they exclude documents where the given field does not exist, as explained in the documentation.
Also, note that a field exists when it's set to any value, including an empty string (""), null, and NaN (not a number).
So, in conclusion, if you want to query for documents where is_correct is not true, you need to create this field in these documents with a value different than true.

How to get all the matching values from '$in' operator in mongoose

I have multiple checkboxes for different categories of blogs -
And what I want to achieve is that when I select some categories and click on filter, the specified selected blogs would be shown. I used query string parameters or URL parameters to send all the selected checkbox values to the nodejs backend -
query is an array containing all the selected categories
const response = await axios.get(`http://localhost:8000/blog/all?categories=${query}`)
And in the backend -
const cat = req.query.categories;
const all = await blogModel.find({ category: { $in: cat } });
I am passing the cat, which again consists of all the selected categories from the frontend, to $in to find all the matching blogs.
But the issue I am facing is that I am not getting matching blogs, say when I select the 'Science' checkbox and click on the filter I am able to get all the blogs having 'Science' as a category. But when I select say 'Science' & 'Food', I am getting an empty array as output even though I do have blogs of both categories in my MongoDB.
Backend console log of cat when I select 'Science' category -
And when I select 'Science' & 'Food' -
I get an empty array as output instead of all the blogs of 'Science' & 'Food' categories.
To summarize , when i select more than one categories i am getting an empty array instead of the blogs of the selected categories.And when i select only one category then i am able to get the selected blogs.It's not working for multiple categories
I am sure I am missing out on something but don't know what to google to get correct results. I also went through similar StackOverflow questions but I was not able to wrap my head around what needs to be done. I am building a simple blog website for my portfolio & thought of adding this 'filter by category' feature so that I would get to learn on how to filter values from MongoDB using mongoose. Please help me resolve this issue. Thank You.
Edit 1 - This is an example of a document from my collection
Also 'console.log(req.query.categories)' outputs this when i select 'Science' & 'Food' from the above checkbox -
I think you didnt path data as array to mongo query
first split by , and then pass to query
const cat = req.query.categories;
cat = cat.split(",")
const all = await blogModel.find({ category: { $in: cat } });
Yes there seems no issue in your query, make sure you are passing right data to backend like you saved "food" as category in database and searching for "Food" it will return empty array as it is case sensitive.
db.Posts.find({category: { $in:["Food","Gaming"]}})
You can also try this way to fetch
db.Posts.aggregate([{$match:{category: {$in:["cat","dog"]}}}])
const cat = req.query.categories;
var splitcat = cat .split(",");
db.Posts.find({category: { $in:splitcat }})

How do I do a joined lookup with search.lookupFields()?

I'm trying to get some information about an item, including the item's subsidiary's logo, which naturally requires joining the item to the subsidiary.
The documentation for search.lookupFields says:
You can use joined-field lookups with this method, with the following syntax:
join_id.field_name
So, I duly request the fields I want, including a join on subsidiary:
require(['N/search'], function(search) {
var item = search.lookupFields({
type: search.Type.ITEM,
id: 2086,
columns: ['itemid', 'displayname', 'subsidiary.logo'],
});
log.debug(item);
});
itemid and displayname are fine, but when I try to join another record I get this error:
{
"type":"error.SuiteScriptError",
"name":"SSS_INVALID_SRCH_COLUMN_JOIN",
"message":"An nlobjSearchColumn contains an invalid column join ID, or is not in proper syntax: logo.",
"stack":["doLookupFields(N/search/searchUtil.js)","<anonymous>(adhoc$-1$debugger.user:2)","<anonymous>(adhoc$-1$debugger.user:1)"],
"cause":{
"type":"internal error",
"code":"SSS_INVALID_SRCH_COLUMN_JOIN",
"details":"An nlobjSearchColumn contains an invalid column join ID, or is not in proper syntax: logo.",
"userEvent":null,
"stackTrace":["doLookupFields(N/search/searchUtil.js)","<anonymous>(adhoc$-1$debugger.user:2)","<anonymous>(adhoc$-1$debugger.user:1)"],
"notifyOff":false
},
"id":"",
"notifyOff":false,
"userFacing":false
}
This seems to happen no matter which record and field I try to join. What am I missing?
Although you can return results from multi-select fields, you cannot join to fields on records referenced by multi-select fields (which the subsidiary field on the item record is). Also, you cannot search the logo field on the subsidiary record (not listed in Search Columns under Subsidiary in the NetSuite Records Browser).
This means you have to load the Subsidiary record to get the logo field. In other words:
require(['N/record', 'N/search'], function(record, search) {
var item = search.lookupFields({
type: search.Type.ITEM,
id: 2086,
columns: ['itemid', 'displayname', 'subsidiary'],
});
var subID = item.subsidiary[0].value; //internal id of *first* subsidiary
var subRec = record.load({
type: record.Type.SUBSIDIARY,
id: subID
});
var logo = subRec.getText('logo'); //gets the file name - use getValue to get its ID instead
});
Note that if multiple subsidiaries are set on the item, this only gets the values for the first one. You could iterate through the item.subsidiary result to handle values for multiple subsidiaries if required.
I believe you can't access to the subsidiary record from a lookupfield, you should do a proper search.
https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2018_2/script/record/item.html
You can only join to tables allowed in the Item search object. Try looking for "Subsidiary..." in the Search Results tab within the UI. It's not there. Use the Schema Browser to determine what fields and joins are available.
You cannot think of a NetSuite search as you would any regular SQL search. You have to be cognizant of which fields and which joins can be utilized via the search object.
As people have mentioned, the subsidiary is not a join field available from the item record, one way to achieve what you are trying to do is:
Make a lookup to get the internal id of the subsidiary belonging to the desired item.
Then make a lookup to get the internal id of the logo image (file cabinet image) belonging to the previous subsidiary.
Make another lookup/load the image file to get the URL of the image/logo
You can try to combine the above steps in a single saved search but I think you might need to load the image file to get the URL.
This won't answer your question, but this may help out in the future. The records browser shows everything that you can search and join on, columns and filters, and field IDs. Very useful when building out searches.
NetSuite Records Browser - 2018.2

How to Match the string from collection after lookup with many collection using mongodb

Here My query
model.db.aggregate([{$lookup: {from: 'orders', localField: 'prod_id',
foreignField: '_id', as: 'Col'}},{$match:{$text:
{$search:'Sale'}}}).exec((err,data) => {console.log(data);}]);
but error showing "$match with $text is only allowed as the first pipeline !!"
I just want to lookup many collection then only I have to match'Search' in all the data what we joined(lookup) before.
mongoDb version: 4.0
Anybody have an idea ? need Help !
Thanks !!
These all are my Example collections:
collection 1 ->
organization ={'_id':ObjectId("5b110a7b84a0442030a1e9cf"),'Org_name':'dhoni institute','Estd':'1945'}
collection 2 -> players= {'_id':ObjectId("45110a7b84a3542030a1e9cf"),'_name':'Ms dhoni','Org_id' = ObjectId("5b110a7b84a0442030a1e9cf") }
I am searching the text string 'dhoni' in Db..then I want all the documents which contains word 'dhoni' from these collections.
How to do ?
db.players.aggregate([{$match:{$text:{$search:'dhoni'}}},
{
$lookup{from:'organization',localField:'_id',foreignField:'Org_id',as:'org'}
}
]).exec((err,data) => {}
this is my code It only matches the string from 'players' collection .I need matched 'players' collection documents as well as 'Organization' collection documents.
I cannot create new collection because after loopup data may be a huge data so
I cannot inserting new large data every time search
How to match the string after lookup ?
As explained in official mongodb documentation,
$text performs a text search on the content of the fields indexed with a text index.
But indexes are reachable only by the first stage of an aggregation query. That's the reason of your error message.
The only way i see for you to use $text/$search is to perform your aggregation (without match stage), adding an $out stage to output to a new collection, create a text index on that collection, and perform your find query with $text/$search criteria.
Hope it helps.

How to filter a view by id field in CouchDB?

I have a view which outputs the following JSON:
{"total_rows":26,"offset":0,"rows":[
{"id":"SIP-13","key":[1506146852518,"SIP-13"],"value":{"clientId":"CLIENT-2","orderCount":2}},
{"id":"SIP-12","key":[1506147024308,"SIP-12"],"value":{"orderCount":1}},
{"id":"SIP-14","key":[1506159901457,"SIP-14"],"value":{"orderCount":1}},
{"id":"SIP-15","key":[1506161053712,"SIP-15"],"value":{"clientId":"CLIENT-2","orderCount":2}},
{"id":"SIP-16","key":[1506448298050,"SIP-16"],"value":{"clientId":"CLIENT-3","orderCount":1}}
]}
...and I want to get the row with id: "SIP-15" here. How can I do that?
You have to use complex keys. The first field indexed can be anything and the second must be SIP-15.
Query :
?startkey=[null,"SIP-15"]&endkey=[{},"SIP-15"]

Resources