Finding a string in MongoDB collection - javascript

I want to implement a minor file system like collection in MongoDB .
So say my object looks like this
{
"\":{
'autoexec.bat':{
name:'autoexec',
filetype:'bat',
size:1302
},
'users':{ /* its own tree */ },
'windows':{
'system':{
'autoexec.bat':{
name:'autoexec',
filetype:'bat',
size:1302123
}
}
}
}
I am wondering how to find the term 'autoexec.bat' in the most effiecient manner , Further for a file tree is there any better way to implement the same in Node.js or C++ ? I wish to implement features like search etc.

I'd say: don't do this in one gigantic document. Let each file be its own document in a collection, with references to parent and (probably) children. Almost all operations are now trivial. You only have to think about efficient way to read/delete the whole tree.

Last week at MongoNYC Kyle Banker gave a nice talk on schema design by example. I think your problem is extremely similar to his first example of musical genre hierarchy.
In effect, every file would have a document in the collection. It would have a parent field to identify its direct parent (directory it's in in your case) and an array of all its ancestors.
The queries that now become easy are
- what directory is file "autoexec.bat" in
- list all files in directory "foo"
- list all files recursively in directory foo (all files with "foo" in its ancestors.
And don't forget, you also have an option of saving the full path name to a file/directory as well as its base name. This allows searching by leading parts of path if the field is indexed. It's also going to be unique, unlike just the file name.
As always, the key pieces of information are all the ways you'll need to query this collection and the performance and load expectations. Without that, it can be easy to pick a schema which will give you some challenges later on.

Related

Recursive RESTAPI Query

For some background, I have a number of enterprise systems management products that run a REST API called Redfish. I can visit the root folder on one such device by going here:
https://ip.of.device/redfish/v1
If I browse the raw JSON from a GET request, the output includes JSON data that look like this. I'm truncating this due to how long it is, so perhaps some JSON syntax errors here.
{
Description: "Data",
AccountService: {
#odata.id: "/redfish/v1/AccountService"
},
CertificateService: {
#odata.id: "/redfish/v1/CertificateService"
}
}
Perhaps in my searching I'm using the wrong terminology, but each of those #odata.id items is basically a 'folder' I can navigate into. Each folder has additional data values, but still more folders. I can capture contents of folders I know about via javascript and parse the JSON simple enough, but there are hundreds of folders here, some multiple layers deep and from one device to the next, sometimes the folders are different.
Due to the size and dynamic nature of this data, is there a way to either recursively query this from an API itself or recursively 'scrape' an API's #odata.id 'folder' structure like this using Javascript? I'm tempted to write a bunch of nested queries in foreach loops, but there's surely a better way to accomplish this.
My eventual goal is to perform this from nodejs, parse the data, then present the data in a web form for a user to select what fields to keep, which we'll store for faster lookups in a mongodb database along with the path to the original data for more targeted api queries later.
Thanks in advance for any suggestions.

How to change Model name to leverage different property in Forge Viewer

I have a .stp file that has random integer name values for model names in the Model Browser but a valid (ie. human readable) Component Name. I would like to replace the default name with the Component Name in the Model Browser for these cases.
I've looked at a couple similar posts on SO but nothing has worked for me as yet (here and here). I'm using version 6.3.1 of the viewer.
In my investigation into where the data is stored, I've found a strings array in the InstanceTree as well as a PropDbLoader (in the ViewerPropertyPanel). The strings array seems to get populated with the name data (in an interesting ASCII array look-up setup) and the PropDbLoader has properties for the models. The name for the model in the Model Browser popup looks to come from within the ModelStructureTreeDelegate class (InstanceTree.getNodeName). I'd like to be able to extend or override the getNodeName and populate it with Component Name but I have (as of yet) not found a way to get at this data in the model tree.
Any insight or direction would be greatly appreciated
Basically you will need to extend/override the default DIV creation behaviour for model tree nodes here and customize to your needs:
ModelStructureTreeDelegate.prototype.createTreeNode
See here for code sample.

Importing directory of json into mongoDB

I have a directory, with several sub-directories, holding a total of about a million JSON files. I need to import this entire thing into mongoDB. I imagine this is a very common problem, but I cannot find any tutorial for how to do so. Is there an easy solution here?
(Or should I write a script to iterate through the directories, read each file into a variable and then insert the content into my db?)
You're basically on the right path.
Iterate through the entire directory, read the files to create a JSON object in your code, and then just store your documents directly into MongoDB.
Take a look at this.
One big problem though: MongoDB stores your documents into Collections, with the condition that every document in your collection has the same general format/structure. Basically each document must have most, if not all of the same properties as each other. Otherwise you're going to have to use something different, or store all of the JSON as a property of an encapsulating document that you can then store.
Something like the following:
{
'_id': 'YOUR_DOCUMENT_ID',
'doc': 'JSON_OR_STRING_OF_YOUR_FILE'
}

How to define Matrix/Link/Cross Table joins in BreezeJS Metadata?

I'm trying to get breeze working with hand generated Metadata, but I can't seem to find documentation covering navigation properties through matrix tables.
the data model is:
Organization
PK:OrganizationID
User
PK:UserID
The table that joins them is:
User_Organization
PK:UserOrganizationID
FK:OrganizationID
FK:UserID
When I retrieve an Organization I want it to have a property "users" which contains an array of User objects.
How do I define this and specify the matrix table in Breeze Metadata, seeing as User does not have an organizationID?
** update
My primary problem is that I'm linking Breeze to Sequelize, so I need to be able to manage this all through the metadata if possible. The first answer below from #Jeremy-Danyow solves the problem with client side code, but I'm looking for a way to present the final object graph to breeze as part of the metadata.
I think this question might be a duplicate of Many-to-many relations in Breeze. There is useful information in the answer there as well as the comments on the answer.
That said, I want to propose a work-around for this part of your question:
When I retrieve an Organization I want it to have a property "users" which contains an array of User objects.
If you were to configure your metadata the supported way you could add a read-only "users" property to your organization entity like this:
function Organization() { }
Organization.prototype.users = function () {
return this.userOrganizations().map(function(userOrganization) { return userOrganization.user() });
};
store.registerEntityTypeCtor('Organization', Organization);
This uses the "Add methods to the constructor" approach documented here.
Edit
Sounds like breeze-sequelize support is in the works and will be released soon. See here and here. If you can afford to wait a little bit you'll have less friction getting this going.

How to search in rad file explorer for current folder including sub folders

I want to use filter in rad file explorer which needs to search current directory including sub folders items.Currently i can search in only main folder but not sub folders items using built in filter box.Some body help me please
That is not available OOB because it is likely to cause performance issues. Nevertheless, you can create such functionality yourself:
Implement a custom FileSystemContentProvider, overriding the ResolveDirectoryAsTree() and ResolveDirectory() methods in the way, described in this help article: http://www.telerik.com/help/aspnet-ajax/fileexplorer-custom-filebrowsercontentprovider.html
Call recursively the ResolveDirectoryAsTree() and ResolveDirectory() methods from your content provider in order to take references to all listed files and folders (e.g. base.ResolveDirectoryAsTree()). Once you gather all the needed data to one place you can make a search through the items in it. Despite of the accuracy of such an implementation, note that this information-gathering would be a slow process, and you might meet performance issues.
You can find more detailed information regarding the custom commands in the following help article: http://www.telerik.com/help/aspnet-ajax/fileexplorer-add-custom-button-context-menu-item.html
There may be other ways to get this done, but I do not know them.

Categories

Resources