w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How do I have a page display new information in Sinatra after a server-side process ends?
In order to use AJAX you have to create an endpoint on your server and use a jQuery or another framework to ease the use of calling the endpoint from javascript. I will paste a short example. The server could look like this: require 'sinatra' set :views, "." get '/' do erb :home end get '/ajax_endpoint' do t1 = Thread.new { sleep 10 } 'Done' #do the job end Put in the views folder (in my case the same as the one the main sinatra app is in) a file with the following content: <html> <script src='http://code.jquery.com/jquery-2.0.3.min.js'></script> <script> window.onload = function() { $.get('/ajax_endpoint', function(data) {$("#the_div").text("Job done!")}) } </script> <body> <div id='the_div'> Loa

Categories : Ruby

Meteor: Could a race condition happen with Meteor.collections on server side?
In Meteor's concurrency model, you can imagine a whole method as an uninterruptible block of stuff that happens. In order for Meteor to switch from running one method midway to say, starting another method, you need to "yield"—the method needs to signal, "I can be interrupted." Methods yield whenever they do something asynchronous, which in practice means any time you do a database update or call a method with a callback in Meteor 0.6.5 and later. Since you give your update call a callback, Meteor will always try to do something in between the call to update and the update's callback. However, in Meteor 0.6.4.2 and earlier, database updates were uninterruptible regardless of the use of callbacks. However, multiple calls to saveOnServer will happen in order and do not cause a race condi

Categories : Javascript

How to find the child project of a parent project which is passed in the 'WHERE' clause and also, to find the duplicate objects
This is most of the answer, as we determined in the interactive chat: SELECT A.projectName as PARENT,COUNT(A.PROJECTNAME) AS PARENTPROJECTCOUNT, B.ProjectName as CHILD, COUNT(B.PROJECTNAME) AS CHILDPROJECT from psprojectitem a INNER JOIN psProjectItem B ON a.objecttype = b.objecttype AND a.objectid1 =b.objectid1 AND a.objectvalue1 = b.objectvalue1 AND a.objectid2 = b.objectid2 AND a.objectvalue2 = b.objectvalue2 AND a.objectid3 = b.objectid3 AND a.objectvalue3 = b.objectvalue3 AND a.objectid4 = b.objectid4 AND a.objectvalue4 = b.objectvalue4 WHERE A.projectname in (SELECT ProjectName from psProjectDefn WHERE lastupdoprid <> 'pplsoft') AND a.projectname <> B.projectName and A.PROJECTNAME = 'AAAA_JOB_KJ' ORDER BY B.PROJECTNAME

Categories : SQL

Export MongoDB collection to CSV or XLSX with Meteor/JavaScript
You could use something like https://github.com/eligrey/FileSaver.js to create a Blob on the browser side and then offer it as a download. client side js var yourCSVData = "Col1Row1,Col2Row1 Col1Row2,Col2Row2"; var blob = new Blob([yourCSVData], {type: "text/csv;charset=utf-8"}); saveAs(blob, "yourfile.csv"); Build your CSV into yourCSVData then you should be able to have the file downloaded very easily. To build your CSV you would have to use some custom javascript. The thing with mongodb is that each document can have a different structure, which is very bad for row/column type documents. You could use something like the fiddle given by Yvegeniy (http://jsfiddle.net/sturtevant/vUnF9/) in the comments above & it might help var data = MyCollection.find().fe

Categories : Javascript

Meteor.js / MongoDB : finding a document's place in a collection
You can find out how many documents have larger popularity: var popularity = Documents.findOne(documentId).popularity; var morePopular = Documents.find({popularity: {$gt: popularity}}).count();

Categories : Javascript

Using the C# driver Is their a better way to duplicate and copy a MongoDB collection?
You can use the "copyDB" database command, which is described at: http://docs.mongodb.org/manual/reference/command/copydb/#dbcmd.copydb In C#, you would run the following on the destination server: var command = new CommandDocument(new BsonElement("copydb", 1), new BsonElement("fromhost", mydbserver), new BsonElement("fromdb", sourcedb), new BsonElement("todb", targetdb)); var client = new MongoClient(mydbserver); var server = client.GetServer(); var db = server.GetDatabase("admin"); db.RunCommand(command);

Categories : C#

mongodb - add column to one collection find based on value in another collection
In MongoDB, the simplest way is probably to handle this with application-side logic and not to try this in a single query. There are many ways to structure your data, but here's one possibility: user_document = { name : "User1", postsIhaveLiked : [ "post1", "post2" ... ] } post_document = { postID : "post1", content : "my awesome blog post" } With this structure, you would first query for the user's user_document. Then, for each post returned, you could check if the post's postID is in that user's "postsIhaveLiked" list. The main idea with this is that you get your data in two steps, not one. This is different from a join, but based on the same underlying idea of using one key (in this case, the postID) to relate two different pieces of data. In gene

Categories : Mongodb

How do I get data from Mongodb to display in Fullcalendar while using meteor.js
Hi rjsandman try search stack for fullcalendar ajax call and JSON call, Load events with does tecnologys and refer to the Fullcalendar documentation. I'm sure you can figure it out. To output your data depending on your server side tecnology you have to send back to your client side like a String or well formed XML with your already formatted events. This is an example on how you can send the events back: XML format: <?xml version="1.0" encoding="UTF-8"?> <root> <events> <event title="Mytitle" start="20-03-2014 10:30:00" end="20-03-2014 12:30:00" allDay=false></event> and so on... </events> </root> JSON format: [ {"title":"Mytitle","start":"20-03-2014 10:30:00","end":"20-03-2014 12:30:00" "allDay":false}, {"title"

Categories : Mongodb

Server side database debugging in Meteor
Start your app with: $ meteor Open a new Terminal window and type: $ meteor mongo This will open the serverside mongo database console. FYI: If you deployed your app to meteor you can access its database console via: $ meteor mongo myapp

Categories : Meteor

How to debug deployed Meteor app on the server side?
Meteor.com's hosting via meteor deploy will kill your app if its not visited for somewhere near 2-4 hours. This doesn't mean that its dead though, if you load it up in your web browser it'll take a couple of seconds extra to get running again. It might take longer if you have a heavy startup load, though. Meteor hasn't brought up details of its paid solutions yet, but if you want to keep your site up for longer it should automatically if it has a visit every hour or two. I'm not suggesting that its the best way to do it, but you could remotely ping it too.

Categories : Debugging

In Meteor, how do I get a node read stream from a collection's find curser?
Have you tried creating a custom function and piping to it? Though this would only work if Users.find() supported .pipe()(again, only if Users.find inherited from node.js streamble object). Kind of like var stream = require('stream') var util = require('util') streamreader = function (){ stream.Writable.call(this) this.end = function() { console.log(this.data) //this.data contains raw data in a string so do what you need to to make it usable, i.e, do a split on ',' or something or whatever it is you need to make it usable db.close() }) } util.inherits(streamreader,stream.Writeable) stream.prototype._write = function (chunk, encoding, callback) { this.data = this.data + chunk.toString('utf8') callback() } Users.find({}).pipe(new streamReader())

Categories : Node Js

How to query username from userId in a collection in Meteor?
So I guess you'd have to either save the username as well as it's own field (or put both id and username in a user object), or search the Users collection for valid usernames, and when you found one use its id to search the Articles DB. The first suggestion would probably be way more efficient I guess.

Categories : Mongodb

How do I find the Collection Membership Information with PowerShell
Rather than connecting to each computer and extracting the information (slow) get it from the straight from the database.... [CmdletBinding()] param ( [string] $hosts = "", [string] $sccmsrv = "", [Parameter(Mandatory=$False,Position=3)] [string] $path = "" ) $usage = "USAGE: List-AdvertCollMembershipSCCM.ps1 -sccmsrv SCCMSERVER -hosts 'host1 host2 host3' -path 'c: empOutfile.csv'" if ($host -and $sccmsrv){ Write-Host "" Write-Host -ForegroundColor Yellow "SCCM Server: $sccmsrv" Write-Host -ForegroundColor Yellow "Looking at hosts: $hosts" #### Function for executing a SQL query with integrated authentication function execSQLQuery ([string]$fSQLServer, [string]$db, [string]$query){ $objConnection = New-Object System.Data.SqlCli

Categories : Powershell

Query for search command with meteor and MongoDB
You could do something like this (psuedo code): clauses = []; if (d!=null) clauses.push( {'Problem.DateTime': RegExp('^'+d)} ); if (p!=null) clauses.push( {'Problem.PID':p} ); if (r!=null) clauses.push( {'Problem.Request':r} ); if (clauses.length == 1) { and_query = clauses[0]; } else { and_query = {$and: clauses}; } return problems.find(and_query);

Categories : Mongodb

Meteor Collection Transform: is it done on the server or on the client? or it depends
You can use transform on both sides, when you specify a transform option to the collection or findOne,fetch,etc transform Function An optional transformation function. Documents will be passed through this function before being returned from fetch or findOne, and before being passed to callbacks of observe, allow, and deny. If you need to get raw document from a collection with transform option. myCollection.findOne({},{transform:null})

Categories : Javascript

How to respond server-side to routes using Meteor and Iron-Router?
Meteor Router (now deprecated) has server side routing support: Meteor.Router.add('/upload', 'POST', function() { // do stuff });

Categories : Meteor

Meteor/Mongodb find related records based on document's tags
It's easy with this structure: [{ title: 'title', tags: ['tag1', 'tag2'], }] Then you use: Documents.find({ tags: {$all: [ "alpha", "beta", "gamma" ]} }); See here: http://docs.mongodb.org/manual/reference/operator/all/#op._S_all Now, it may or may not work with complex objects as you have, I'm not sure. Try this: Documents.find({ tags: {$all: [{name: "alpha"}, {name: "beta"}]} }); If you need the specified structure and the above query does not work, you're left with the $where query. It is very flexible, but not recommended as it's much slower than the others. See here: http://docs.mongodb.org/manual/reference/operator/where/#op._S_where     EDIT: this one should do the job: Documents.find({ 'tags.name': {$all: ["alpha", "beta"]} });

Categories : Mongodb

Mongodb. Cannot find defined collection in C#
You must add a Class like code below var connectionString = "mongodb://localhost"; var client = new MongoClient(connectionString); var server = client.GetServer(); var database = server.GetDatabase("testdb"); // "testdb" is the name of the database // "Users" is the name of the collection var collection = database.GetCollection<Entity>("Users"); // var searchQuery = Query.EQ("firstname", "Tom"); var cursor = collection.FindAll(); what is Entity? -It's the class i'm telling yout about to get and set fields inside this collection. In my case,it should look like this : class Entity { public ObjectId Id { get; set; } public string firstname { get; set; } public string lastname { get; set; } }

Categories : C#

How to query mongo using virtual attributes from Collection.transform in meteor
Here's how you would get all "contacts" out of this, perhaps in an inefficient way: var allContacts = []; customers.find().forEach(function(customer){ var contacts = customer.neverContacted(); contacts.forEach(function(contact){ allContacts.push(contact); //You will want to have an if here to check if it already contains that contact already. }); }); Another option: setupSearches(customers.find()).contacts() setupSearches = function(input){ input.contacts = function () { contacts = input.find({customer_id: this._id}).fetch(); return contacts; } return input; }

Categories : Mongodb

Meteor server-side memory usage for thousands of concurrent users
Take a look at this post by Arunoda at his meteorhacks.com blog: http://meteorhacks.com/making-meteor-500-faster-with-smart-collections.html which talks about his Smart Collections page: http://meteorhacks.com/introducing-smart-collections.html He created an alternative Collection stack which has succeeded in it's goals for speed, efficiency (memory & cpu) and scalability (you can see a graphed comparison in the post). Admittedly in his tests RAM usage was negligent with both Collection types, although the way he's implemented things there should be a very obvious difference with the type of use case you mentioned. Also, you can see in this post on meteor-core: https://groups.google.com/d/msg/meteor-core/jG1KLObX1bM/39aP4kxqWZUJ that the Meteor developers are aware of his work and

Categories : Meteor

How to manage and selectively stop a published subscription from Meteor server side code
Create two separate subscriptions that both return game data. One subscription should return public game data, the other should return game data that is viewable by the currentUser. They will be merged into one collection on the client side. Games the user has joined will contain private info AND public info, games they haven't joined will only contain public info. Then on the client side, a liveQuery like Game.findOne(thisGame.id) will automatically receive the private information when the player joins the game and cause your template to be re-rendered, etc. Pseudo-code for illustrative purposes: if Meteor.isClient Meteor.subscribe 'GameInstances' Meteor.subscribe 'MyGameInstances', guestId join = (gameInstanceId, spot) -> Meteor.call "join", gameInstanceId, spot, (er

Categories : Meteor

How to get user's information from Facebook in the server side (PHP) in an Android application
You should be able to do something like this: $facebook->setAccessToken("...."); The token is the one that you get on Android. You should be able to make calls to the api now, with the new token you've assigned the object with. var_dump($facebook->api('/me'));

Categories : PHP

[only equal operator]what are the fast algorithms to find duplicate elements in a collection and group them?
For your answer, though I am not 100% sure that you want this is only. If you want good algo try Binary search tree creation. as it is a group,and according to BST properties you can easily group elements. For Example BST() { count = 0; if(elementinserted) count = 1; if(newelement == already inserted element) { count++; put element in array upto count value; } } I hope this explanation can help you.

Categories : C++

Find absolute base path of the project directory (after Meteor 0.6.5)
I ran into the same predicament when I updated to 0.6.5. What I'm currently doing is getting the path like this: var meteor_root = Npm.require('fs').realpathSync( process.cwd() + '/../' ); This returns on dev mode: /my/application/.meteor/local/build/programs and on bundled mode: /my/application/build/app/programs So from here I'm getting to my application's "root" path like so: var application_root = Npm.require('fs').realpathSync( meteor_root + '/../' ); // if running on dev mode if( Npm.require('path').basename( Npm.require('fs').realpathSync( meteor_root + '/../../../' ) ) == '.meteor' ){ application_root = Npm.require('fs').realpathSync( meteor_root + '/../../../../' ); } The only case in which this would fail is if you happen to name your application's folder ".met

Categories : Node Js

PHP MongoDb, find all referenced documents when collection is indexed array
I don't quite see why you have such a complicated structure. Particularily the "0" and "1" keys are problematic, especially dealing with PHP as it doesn't really like arrays with numerical string keys. The $ref/$id fields come from MongoDBRef, which should avoid as they don't provide you with any functionality. You should just have: { "_id": ObjectId("5188deba4c2c989909000000"), "_type": "Model_Discs", "title": "really cool cd", "referencedBy": [ ObjectId("4e171cade3a9f23359e98552"), ObjectId("5045c3222b0a82ec46000000") ] } Then you can simply query with: db.collection.find( { referencedBy: new ObjectId("5045c3222b0a82ec46000000") } );

Categories : PHP

MongoDB query comparing 2 fields in same collection for php
The SERVER-7623 ticket that Mason referred to in his comment above will definitely support this, after it is implemented. For the time being, you will have to resort to the $where query operator, which takes a string of JavaScript code and allows you select documents where the expression would evaluate to true (the current document is available as this). There are examples in the documentation that cover your exact use case. Be aware of the performance caveats of $where (e.g. regarding indexes), which are also discussed there.

Categories : PHP

MongoDB cross-collection query with casbah
Of course you can do this in casbah - remember db.flags.distinct returns an iterable that should be converted implicitly to a list for use in $in. Heres a test example for you: import com.mongodb.casbah.Imports._ val db = MongoClient()("casbahTest") val customers = db("customers") val flags = db("flags") customers.drop() flags.drop() // Add some customers customers += MongoDBObject("_id" -> 1, "name" -> "foo") customers += MongoDBObject("_id" -> 2, "name" -> "bar") customers += MongoDBObject("_id" -> 3, "name" -> "baz") // Add some flags flags += MongoDBObject("cid" -> 1) flags += MongoDBObject("cid" -> 3) // Query // In JS: db.customers.find({id: {$in: db.flags.distinct("cid", {})}}) // Long hand: customers.find(MongoDBObject("_id" -> MongoDBObject("$in"

Categories : Mongodb

How to display a collection in View of ASP.NET MVC 4 Razor project?
See the view below. You simply foreach over your collection and display the Contracts. Controller: public class ContactsController : Controller { public ActionResult Index() { var model = // your model return View(model); } } View: <table class="grid"> <tr> <th>Foo</th> </tr> <% foreach (var item in Model) { %> <tr> <td class="left"><%: item.Foo %></td> </tr> <% } %> </table> Razor: @model IEnumerable<ContractPlain> <table class="grid"> <tr> <th>Foo</th> </tr> @foreach (var item in Model) { <tr> <td class="left"><@item.Foo></td> </tr> @} </table>

Categories : C#

Meteor, How can I display a url query in the client?
It might be easier to use something like meteor-router. Then you could do server side js: Meteor.Router.add('/something', function() { return this.params.yourname; }); So if you visited example.com/something?yourname=Bob you would get back Bob. Be careful when displaying something directly to the client from a querystring/input parameter as if you don't check it before it could be used for XSS.

Categories : Meteor

How can i modify the mongodb query to suit the collection structure
If you need to search by expiration date, just add another field to the query calling put (wasn't it append by the way?) again. If you need performances, define an index on the field you're using to query the collection.

Categories : Java

Does server-side javascript function have performance issues in mongoDB?
It is recommended within the documentation not to use stored JavaScript procedures within MongoDB. I kind of still refuse to call it "server-side" since that denotes that it works "in" MongoDB which it does not, they are not stored procedures. Anyway, by default JavaScript functions take global lock, which can be mitigated with nolock and V8 (default since 2.4) can multithread; so it does seem as though this is usable but there are other problems: eval runs on the primary of a replica set and only the primary eval does not work with sharded collections still eval must have full admin access to run at all with auth enabled (this means using an admin user in your application) eval runs in a self contained JavaScript environment which when run with admin acess has full access to your da

Categories : Javascript

How to replace the ObjectId ref. with with the actual object from MongoDB (idealy on the server side)?
As @WiredPrairie said, you need to use the populate function Populate Mongoose Documentation Your query should look like this: app.get('/news', function(req, res, next){ News. find(). populate("addedBy"). exec(function(err, nws){ if(err) {res.writeHead(500, err.message)} res.send(nws); }); }); There are plenty of different things that you can do with populate, for example to bring only the username field of the "addedBy" document, you can do populate("addedBy","username") or if you don't want bring one specific field, doing something like this: populate("addedBy","-username")

Categories : Node Js

How do I make a news feed which continuously updates with information from a database using continuous server-side processing?
If you really have to have a continuous feed then take a look at WebSockets. However, you probably only need a polled solution for this, refreshing every few seconds. There's a sample implementation here

Categories : PHP

find a control with no runat='server' from server side
You could do conversationdiv.InnerHtml... in this specific case it would return the HTML of the table. You could then use HTML Agility Pack to query or manipulate the said table. Example var html = new HtmlAgilityPack.HtmlDocument(); html.LoadHtml(conversationdiv.InnerHtml); var table = html.DocumentNode.SelectNodes("table").FirstOrDefault(); var tr = table.SelectNodes("tr").FirstOrDefault(); var td = tr.SelectNodes("td").FirstOrDefault(); var blahBlah = td.InnerText;

Categories : C#

We don't need to stop running project due to server side datas changes
To see the immediate changes you can copy your js files and paste it in your target folder of entrypoint project. And a browser refresh will suffice. Sometimes clearing of browser cache also required. This might not be a classy solution but it will reflect the changes and in cases where you don't want to restart the server again and again to check whether it works or not.

Categories : Gwt

MongoDb java async driver : What is the correct query for sorting and limiting values from a collection
I don't think that the Aggregation framework is the right choice here. I would just do a straight 'find'. There is a Find class and nested Find.Builder class for constructing the more complex queries. import static com.allanbank.mongodb.builder.QueryBuilder.where; import com.allanbank.mongodb.MongoClient; import com.allanbank.mongodb.MongoCollection; import com.allanbank.mongodb.MongoFactory; import com.allanbank.mongodb.MongoIterator; import com.allanbank.mongodb.bson.Document; import com.allanbank.mongodb.builder.Find; import com.allanbank.mongodb.builder.Sort; public class StackOverFlow { // SELECT * FROM collect // WHERE time >= input1 AND userId = input2 // ORDER BY time DESC // LIMIT 30 public static void query(long input1, String input2) { MongoCl

Categories : Sorting

How to display ping information of a server on the stage in AS3
Im not sure if this is what you are asking, but if you want to show the information that is being traced right now, you have to have a textfield on the stage, or create one dynamically. You could do it like this you want to make a text field: import flash.text.TextField; function ldrStatus(evt:*):void{ if(evt.status == 200) { time_stop = getTimer(); trace("got response in", time_stop - time_start, "ms"); var tf:TextField = new TextField(); addChild(tf); tf.text = "got response in"+ (time_stop - time_start) + "ms"; } times++; if(times < limit) doThePing(); }

Categories : Actionscript

SQL Server Find Duplicate dates with the same ID
If you need to return the rows, then you want to use a window function: select [uniqueID], [requirementId], [number], [description], [dtmexecuted], [amount] from (select t.*, count(*) over (partition by requirementid, dtmexecuted) as cnt from MyTable t ) t where cnt > 1

Categories : SQL

How to display a JDialog on Host Side for a Server App
Here is my answer coming from the comments. I think is is better to not post further comments on the question since it looks more like a chat ;-) but there are still many points that remain unclear, very unclear. First I will suggest you to have look for deployment tools that might to what you intend out of the box. It could spare you some time. If your clients work on windows machines, why not send them MSI file? Anyway from what I understood, your update consist (among other?) of executing SQL scripts on a local embedded database. If so, RMI could be a good and simple solution but you have to keep in mind that you will need to deploy your java app and its dependencies on all the clients and that is should be launched on startup. You will also need a mechanism to to specify what can

Categories : Java

Meteor.js: having multiple subscriptions on one collection enforce storage results in one local collection(Workarounds?)
If you want your client side collection to have a different name from the server side collection you can not just return a collection cursor. This can be done in the publish function though like this: Meteor.publish("details", function (id) { //details here matches the subscribe request var self = this; self.added( "details", id, collection.findOne({_id: id}); //details here tells the client which collection holds the data self.ready(); }); This will not be reactive but can be made that way by using observe as in the counts by room example at http://docs.meteor.com which is explained in detail here How does the messages-count example in Meteor docs work?. While this answers your question of how to get a specific name for a collection without having that collection on the serv

Categories : Meteor



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.