Meteor minimongo insert method not working - meteor

I was following the meteor tutorial from meteortips and I got to the part where you create a collection in the browser's console. Creating the collection works, but it doesn't let me insert anything into it.(PlayersList = new Meteor.Collection('players');)
Please see below:
PlayersList.insert({ name: 'Alex', score: 42 });
"rpPamgZEZM9opCzHz"
debug.js:41 insert failed: Method not found
What's weirder is that I even get back the hash as if the insert worked.
Typing PlayersList.find().fetch(); returns an empty array :(
I'm using the latest version of Meteor on Windows 8.1 with MongoDB version 2.6
If anybody could help me, I would be very thankful :)

You have defined the collection PlayersList = new Meteor.Collection('players'); on the client but it has not been defined on the server.
If you have something like if(Meteor.isClient) {..} (or in the /client) directory the code won't run on the server. Make sure you also place a PlayersList = new Meteor.Collection('players'); in the if(Meteor.isServer) (or the /server) directory.
The best thing to do is place it outside both in the root directory so it runs on both the client and server.
When you insert the document on the client the message is transmitted to the the server & it tries to insert it into the database. The collection isn't defined on the server side so it rejects it with the message method not found.

Related

RavenDb patch api in embedded version of the server

Is there any difference in patch api in embedded and standard version of the server?
Is there a need to configure document store in some way to enable patch api?
I'm writing a test which use embedded raven. The code works correctly on the standard version but in test it doesn't. I'm constantly receiving patch result: DocumentDoesNotExists. I`ve checked with debugger and the document exists in the store - so it is not a problem with test.
Here you can find a repro of my issue: https://gist.github.com/pblachut/c2e0e227fa3beb51f4f9403505c292bb
I`ve reached the contact in the ravendb support and I have answer for my question.
There should be no difference between embedded and normal version of the server. The problem was that I did not passed explicitly for which database I want to invoke batch command. In the result I tried to patch document in system database.
var result = await documentStore.AsyncDatabaseCommands.ForDatabase("testDb).BatchAsync(new[] {command});
I assumed that database name will be taken from the session (beacuse I get documentStore from there). But the name of database should be always passed.
var documentStore = session.Advanced.DocumentStore;

MarkLogic I don't know how to get all the result

Hello I am trying to read a module with this code:
(: Entry point - must be a read-only query. :)
xdmp:invoke(
'/path/mydocument.xqy',
(xs:QName('var1'), 'test',
xs:QName('var2'), "response"))
I am new in MarkLogic, I am using groovy and the api to connect to it, but also I saw I can invoke the module with this and indeed I did but it returns me
your query returned an empty sequence
I want to know if I can query xs:QName('var1'), 'test', changing test with a wildcard or how can I get all the information from the file called /path/mydocument.xqy?
I tried to use this:
xdmp:document-get("/path/mydocument.xqy)
but it says the file is not found. Although, if I use invoke I can query it, but I don't know what are the values I have to pass. I was wondering if there is something like sql using %% or something to give me all the data.
To answer the first question: "I am trying to read a module "
IF the module is in the database, then you must query the Modules database in which the module resides.
If the module is in the filesystem then you cannot directly access its source as a document but you can by executing xdmp:filesystem-file()
Simplification:
With the Default configuration of the server and REST client, user placed modules are in the "Modules" database and user placed documents are in the "Documents" database. This means, if you do a GET (read a "Document") with no additional parameters, it will return documents from the "Documents" database. Assuming you are using the default configuration for client and server, this would result in the behavior you are seeing. E.g. your Module code is in the Modules database, doing a GET for it by name will search the Documents database and correctly not find it.
You don't mention, and I don't know, the groovy library being used, but the REST API itself and all implementations of general purpose ML REST client libraries I am familiar with have options for overriding the default database with another. If the groovy library supports that, then specify the "Modules" database for your query and it should return the module document. Note: content-type will be application/text not text/xml.
You can simplify things for testing by bypassing the libraries and simply use a browser and try a URL like this http://yourserver.com:8000/v1/documents?uri=/your/module.xqy&database=Modules
Ref: https://docs.marklogic.com/REST/GET/v1/documents
Making the appropriate changes to the path and server for your use.
If you are still confused, then you should start with the basic MarkLogic tutorials and work through them one by one. You will most likely succeed faster by doing this then jumping straight into coding you don't understand yet.
DETAIL:
Note: The default behaviour is to EXECUTE documents when doing a GET call, using the Modules database. Thus doing a GET of http://yourserver:8000/your/module.xqy will EXECUTE it not return its source.
You will notice the REST API has a uri query parameter. This is EXECUTING the REST API code on /v1/documents which in turn will read the document specified by the uri and database parameters and return it.
I guess I can use:
xdmp:invoke(/pview/get-pview-browse-profiles.xqy,
cts:and-query((
cts:element-value-query(
xs:QName("letter"),"*", "wildcarded"),
cts:element-value-query(
xs:QName("collection"),"*", "wildcarded"))))
although it doesn't return anything

Web2py Error" <class 'sqlite3.OperationalError'> no such table: application

When I try to add a new record to Web2py Database I get this error. I've moved the repository from a different machine but all of my files are same.
My previous database DAL connection parameters are as follow:
from gluon.contrib.appconfig import AppConfig
myconf = AppConfig(reload=True)
if not request.env.web2py_runtime_gae:
db = DAL(myconf.get('db.'+myconf.get('db.mode')+'_uri'),
pool_size=myconf.get('db.pool_size'),
migrate=myconf.get('db.migrate'),
migrate_enabled=myconf.get('db.migrate_enabled'),
#fake_migrate_all=myconf.get('db.fake_migrate_all'),
fake_migrate_all=True,
check_reserved=['all'])
else:
db = DAL('google:datastore+ndb')
session.connect(request, response, db=db)
It was giving me user_auth not found error so I changed it into this by following the official docs:
from gluon.contrib.appconfig import AppConfig
myconf = AppConfig(reload=True)
if not request.env.web2py_runtime_gae:
db = DAL('sqlite://storage.sqlite', pool_size=1, check_reserved=['all'], migrate=False, fake_migrate_all=True)
else:
db = DAL('google:datastore+ndb')
It shows all the table in /database and in "Database_Administration" console I try to add a new record I get the error below.
Web2py Error" <class 'sqlite3.OperationalError'> no such table: application
There is no table in my app named "application" so it has to be related to app. Please advise.
Go to your database folder in "applications/yourappname/databases". Remove all the tables and then recreate tables. You must had copied it from somewhere and couldn't get all the tables loaded. Set migrate=True and fake_migrate_all=false. Then rerun server and go to your app in web2py server panel. Select "Edit" and go to "database administration" under "Models" on the admin panel. You will get all the tables recreated on your own machine. If this is not the case that you've copied from some other source....still do the following by deleting all the tables. You will surely get it up and running.
You have created a completely new database, but by setting fake_migrate_all=True, you have made web2py think all the tables have been created even though they never were. Instead, you should initially leave migrate=True (the default), and do not set fake_migrate_all. In that case, web2py will create the tables upon the first request (after that, you can disable migrations until you need to make another change).

error in azure portal when trying to view all registered stored procedures in documentdb: Failed to get scripts

I created a couple of API methods based on this explanation to create stored procedures with Powershell for documentdb.
When trying to check if the stored procedures are indeed in the portal available, I receive an error that says:
Failed to get scripts. Please try again.
I can retrieve the registered stored procedures with another API call from powershell, and I can also delete the stored procedures without any error message. When I deleted all the scripts, the error message disappears too. So the Portal does recognize that I registered stored procedures, but it seems it just fails to visualize them.
Failed to get scripts. Please try again.
I could reproduce the issue on my side, if the body of the stored procedure contains \r\n and write it in multi lines.
$requestbody = '{"id":"TestSprocf","body":"function (name){\r\n
var response = getContext().getResponse();
\r\nresponse.setBody(name);
\r\n}"}'
$response = Invoke-RestMethod -Uri $uri -Method POST -Headers $hdrs -Body $requestbody
Click Refresh button in Script Explorer, notification with failed error message will appear.
Please check the body of your stored procedure to make sure it is written in above format.

What does it mean when a Collection insert results in a 404?

I have a very simple test app in meteor, and I've created a collection like so:
var people = new Meteor.Collection("people");
When I try to do a simple insert, like this:
people.insert({name: "Benson"});
I get a 404 error with the text "Method not found". I admit there's a good chance I've fat-fingered something here, but I'd love to know both what's wrong, and why the error is so opaque (i.e. where it's coming from).
This error almost certainly means you've only defined people on the client, but not on the server. The new Meteor.Collection('people') declaration has to also run on the server, or else the server doesn't know how to run your insert command.
Be sure you're calling new Meteor.Collection on both the client and the server. Are you calling it inside if (Meteor.is_client), or in a file under the client subdirectory?
Some more details: On the server, new Meteor.Collection defines three remote methods (Meteor.methods) that insert, update, and remove documents in the named MongoDB collection. On the client, the same command creates an in-memory minimongo collection that lives inside the browser, and defines three stubs that simulate the methods by applying the same change to the minimongo collection. By only declaring the collection on the client, your client code runs the local insert just fine, but when it asks the server to perform the real insert, the server has no idea what method you've asked it to execute.
If you want to use Collection only on Client side and you don't need to save that data to server you can declare your collection in "client" folder or in .isClient() function by passing null to the constructor like this:
if(Meteor.isClient()){
// Some other code
...
onlyClientCollection = new Meteor.Collection(null);
// Some other code
...
}

Resources