I'm relatively new to Meteor and I was wondering how I manually edit the mongoDB for Meteor Collections.
If I declare a new collection on both the client and server:
People = new Meteor.Collection("people");
Then I create an array of names on the server and insert it into the collection:
var names = ["Dan", "Bob", "Sarah"];
for(var i=0; i<names.length; i++)
{
People.insert({name: names[i]});
}
How do I add fields to the database and/or change fields in the database manually for development purpose? If I retype the names in the 'names' array and relaunch the app, it doesn't update the database on the server like I expected it would.
Thanks!
Use the javascript developer console in chrome/safari or firebug in firefox
while your app is running you can edit your names.
Your changes will be done live so you can debug and play around quite alot. Something like this might work:
People.find().fetch()
=> lists all the people
Edit one
People.update("_id value from above of the person", {$set:{name:"New Name"}})
Why the method you're using isn't working:
Meteor won't add the names again to the People collection if its already populated. So just run meteor reset to clear everything in your collection. And run meteor again to use your new updated values
Related
I have a general MongoDB question as I have recently found an issue with how I store things.
Currently, there is a collection called spaces like this:
{
_id: 5e1c4689429a8a0decf16f69,
challengers: [
5dfa24dce9cbc0180fb60226,
5dfa26f46719311869ac1756,
5dfa270c6719311869ac1757
],
tasks: [],
owner: 5dfa24dce9cbc0180fb60226,
name: 'testSpace',
description: 'testSpace'
}
As you can see, this has a challengers array, in which we store the ID of the User.
Would it be okey, if instead of storing the ID, I would store the entire User object, minus fields such as password etc?
Or should I continue with this reference path of referring to the ID of other documents?
The problem I have with this, is that when I want to go through all the spaces that a user has, I want to see what members are a part of that space (challengers array). However, I receive the IDS instead of name and email obviously. I am therefore struggling with sending the correct data to the frontend (I have tried doing some manual manipulation without luck).
So, if I have to continue the path of reference, then I will need to solve my problem somehow.
If it is okey to store the entire object in the array, It would be a lot easier.
HOWEVER, I want to do what is the best practice.
Thank you everyone!
I Want to change field length through a PHP script and Sugar beans in both database and Sugar CRM studio
You're question is very vage and doesn't show us what you've already tried, but I'll give it a go regardless:
Custom fields
Studio saves custom fields in DynamicFields beans, which are saved in database in the fields_meta_data table. The field's id is module name + field name, e.g. Accountstests_c for field test_c.
One way to change it is by updating the len column in the table and then run a Quick Repair & Rebuild (see notes below).
Alternatively you could adjust the field using the DynamicFields beans or using the ModuleBuilder's PHP controller similar to how Studio does it (I'll try to add an examples later).
Stock fields
You can adjust a field's length using Vardefs-Extensions.
E.g. if you want to change length (vardef attribute len) of the varchar-field name in module Accounts to 100:
./custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_name.php:
<?php
$dictionary['Account']['fields']['name']['len'] = 100;
Notes
Run a Quick Repair & Rebuild and your change will be applied in Sugar and Studio. Then scroll down and run the suggested DB changes.
If you want to do this without user interaction find or write a sugarcrm repair script.
When creating new Vardef extensions make sure to use the BeanName for the dictionary array index, so Account for Accounts or aCase for Cases. If unsure what to use, just see how existing vardefs files of the module in question do it.
For available vardefs attribute names and more insight into vardefs see here or look at the vardefs.php files in the modules/ subfolders.
I wonder, How do I change a live data schema with MongoDB ?
For example If I have "Users" collection with the following document:
var user = {
_id:123312,
name:"name",
age:12,
address:{
country:"",
city:"",
location:""
}
};
now, in a new version of my application, if I add a new property to "User" entity, let us say weight, tall or adult ( based on users year ), How to change all the current live data which does not have adult property. I read MapReduce and group aggregation command but, they seem to be comfortable and suitable for analytic operation or other calculations, or I am wrong.
So what is the best way to change your current running data schema in MongoDB ?
It really depends upon your programming language. MongoDB is really good at having a dynamic schema. I think your pattern of thought at the moment is too SQL related whereby you believe that all rows, even if they do not yet have a value, must have the new field.
The reality is quite different. The rows which have nothing meaningful to put into them do not require the field and you can, in your application, just check to see if the returned document has a value, if not then you can assume, as in a fixed SQL schema, that the value is null.
So this is one aspect where MongoDB shines, is the fact that you don't have to apply that new field to the entire schema on demand, instead you can lazy fill it as data is entered by the user.
So just code the field into your application and let the user do the work for you.
The best way to add this field is to write a loop, in maybe the console close or on the primary of your replica (if you have one, otherwise just on the server), like so:
db.users.find().forEach(function(doc){
doc.weight = '44 stone';
db.users.save(doc);
});
That is currently the best way to do something like what your asking.
I am using Lucene.Net (version 2.9.4.1) to implement a simple search module. I'm trying to delete the document if it exists in the index using the following code,
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
var indexWriter = new IndexWriter(
LuceneSearch._luceneDir,
analyzer,
IndexWriter.MaxFieldLength.UNLIMITED);
var searchQuery = new TermQuery(new Term("ListID", listingDoc.Get("ListID")));
indexWriter.DeleteDocuments(searchQuery);
where listingDoc is of type Document i'm trying to delete the document if it exists and then add it again to the index, the adding part works fine but the deleting part is not working that is the document is not deleted if it exists. Therefore if i search a term and it matches it is shown multiple times... Please point out what iam doing wrong here
I am using ASP.Net MVC3 and Entity Framework4. every time a record is updated i intend to update the index but instead its been duplicated. and when i search it i get the result twice or thrice depending upon the number of times i do the update.
I tried using indexWriter.UpdateDocument(args); to no avail...
When debugging deletions it can sometimes be useful to perform a search with the same parameters as the delete command, to see exactly what is going to get deleted.
If you're doing a deleteDocuments(query) you should use an IndexSearcher like this:
IndexSearcher is = new IndexSearcher(indexWriter.GetReader());
TopDocs topDocs = is.Search(query, 100);
And see what you get in the topDocs. I suspect you'll find that the query doesn't return any results.
You can do it by simply:
Query query = queryParser.parse("My Query!");
writer.deleteDocuments(query);
I am developing a webapp using PHP and MongoDB. In this app I keep two collections. One to keep data about files and one to keep track about download events for each file.
I need to get the 10 latest downloaded files but I know joins is not an option. The events document only stores the file id and the other collection stores the thumbnail.
Right now I first get the 10 recently downloaded files and order it by date and the order is fine but then I use this array of files (their ids) and make a where_in query where I look for files whos id is present in the ids array. This also works fine (I get the thumbnails for the selected files) but I cannot keep the order anymore. The most recently downloaded file is not longer on top.
How can I keep the order of the ids without looping through them thus making 10 new queries instead of just one?
I cannot change the schema because I got over 40.000 documents :)
UPDATE
In short this is what I want to do:
Get all the IDs of the 10 recently downloaded files. Sorted by download timestamp.
Use this array of Ids and make a query to the files collection and get the details for each file like thumbnail, decription and so on.
The above steps works fine, BUT I cannot keep the order from the first step thus I cannot get the most recently downloaded file on top. I know I could look trought the id array and get data for each file but that would cost me 10 queries instead of one.
I don't really get your problem. Here's some pseudo-code:
// get last N download events
events = get_latest_downloads()
// retrieve associated file data
file_array = get_all_file_info_by_events(events)
display_data = []
for(e in events) {
data = find_file_info_in_the_array(file_array, e.file_id)
display_data.push(data)
}
// now display_data is contains full file info, sorted by download time.