w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Firefox behaves differently from other browsers if anchors are clicked on a page which was created using document.write. Is there a workaround?
Hi ran a few tests using ie8 ie9 and chrome, then did a bit of research. When your building your website and test it locally the javascript or in your case script wont always run on ie8 or ie9 because your active x controls are turnd off, but if you were to upload your page onto a server and then test it you will see that the document.write will indeed work online. I tested the following online and then ofline and it workd online <head> <title>Untitled Page</title> <script type="text/javascript"> function myFunction() { document.write("text <a href="#a">link</a>"); document.close(); } </script> </head> <body> <label onclick='document.write("text <a href="#a">link</a>");document.close();'>click</l

Categories : Javascript

How to protect SharePoint Document (Read only and not allow to download)
Applying information rights management might help you achieve this. Have a look at the following link http://office.microsoft.com/en-in/sharepoint-server-help/apply-information-rights-management-to-a-list-or-library-HA101790603.aspx

Categories : Sharepoint

XPath evaluation in dom4j Document created from org.w3c.dom.Document doesn't work as expected
Change your xml loading as follows: DocumentBuilderFactory docBuilderFactor = DocumentBuilderFactory.newInstance(); docBuilderFactor.setNamespaceAware(true); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

Categories : Java

MongoDB - How to Determine Date Created for Dynamically Created DBs and Collections?
For database: You can check the creation time for "database-name.ns" file ls -l test.ns -rw------- 1 root root 16777216 Jun 12 07:10 test.ns For collection: Most of time collection is created when you insert something into it. So, if you are not creating the collection using createCollection() command and you are using the default ObjectId for _id key, then you can get a rough estimate of the creation of the collection by knowing the time at which the first document inserted in that collection. Mongo > db.test.find().sort({$natural : 1}).limit(1).toArray()[0]._id.getTimestamp() ISODate("2013-06-12T01:40:04Z")

Categories : Database

update nth document in a nested array document in mongodb
Q1: If you update with permalink 'jaiho' instead of 'haha', it most certainly updates the email; > db.posts.update({"permalink" : "jaiho"},{$set:{"comments.0.email":1}}) > db.posts.find() ..., "email" : 1 },... Q2: Same goes for this include; > db.posts.update({"permalink" : "jaiho"},{$inc:{"comments.0.num_likes":1}}) > db.posts.find() ..., "num_likes" : 1 },...

Categories : Arrays

IE10 issue executing function after document open but before document write?
You mention you're writing to an IFRAME. You can call this from IFRAME parent <iframe id="ifr"></iframe> <script type="text/javascript"> document.getElementById("ifr").contentWindow.document.open(); alert("Opened document"); document.getElementById("ifr").contentWindow.document.write("Hello World"); alert("Wrote to document"); document.getElementById("ifr").contentWindow.document.close(); alert("Closed document"); </script> Seems to work in IE as well.

Categories : Javascript

Javascript, Firefox replacing entire document without document.write
I would recommend you to make use of the .html() function of jQuery. (or innerHTML if you prefer to make use of pure Javascript) If the document DOM has already been loaded you shouldn't be using document.write.

Categories : Javascript

MongoDB: If document exists VS If document does not exist
The question is how you determine that "the document" exists? Usually, you'd do this using a unique id. Now MongoDB's ObjectId comes to the rescue because it contains a timestamp already. This can also be used in queries. Instead of using an integer field User_ID, you might want to consider calling the field _id and use the ObjectId data type so you get that functionality for free. > db.test.insert({"foo" : "test"}); { "_id" : ObjectId("51cb763e58bb4077aea65b3d"), "foo" : "test" } > var foo = db.test.findOne(); > foo._id.getTimestamp(); ISODate("2013-06-26T23:16:14Z")

Categories : Mongodb

Javascript - document.write() is working but document.innerHTML isn't
Am I doing something incorrectly? Yes, your timer logic is flawed. Currently you're doing function fn() { if (/* no time left*/) { clearTimeout(timer); // show end message } // show countdown var timer = setTimeout(fn, 1000); } You're trying to clear the timer before you've started it. And actually you don't have to do that at all, since at that time no timer is running. What you have to do instead is ensure that the timer is not restarted. So change the logic to function fn() { if (/* no time left*/) { // show end message } else { // show countdown setTimeout(fn, 1000); } } Of course that doesn't really explain why your innerHTML assignment is not working (unless the flawed timer-cancelling led to some exceptio

Categories : Javascript

Mongodb: Store a tree as one nested document or store one document per node?
It looks like you are going to lots of operations in different levels of nested nodes in the tree. Although MongoDB can store a structure like you describe, it is not very good at allowing you to do update at lots of nested levels. Therefore I would recommend you to store each node as it's own document, and look at where you store the parent-child relations. Remember to optimise the schema for data operations. I'd go with your "way 1" in this case. If you would not have to change the tree a lot, and you have say 1000x more read than write operations to the tree, then you could consider using "way 2" and just deal with the extra work it takes to update the nodes at a few levels deep.

Categories : Json

Set the name of the document when it is created
The makeCopy method includes the possibility to give a name to the copy, the autocomplete shows it clearly So in your code you could do it like this : function generateDocument(e) { var template = DocsList.getFileById(e.parameter.Templates); var Sheet = SpreadsheetApp.getActiveSpreadsheet();// I moved this line a bit to have Sheet available var row = e.parameter.row var myDocID = template.makeCopy(Sheet.getRange('E'+row).getValue()+'-'+Sheet.getRange('D'+row).getValue()).getId();// this is a basic implementation to compose the name with content of column D and E separated by a hyphen... customize it the way you want. ...

Categories : Google Apps Script

Get the first document using $in with mongodb
You cannot add a limit to $in but you could cheat by using the aggregation framework: db.collection.aggregate([ {$match:{serial:{$in:[list_of_serials]}}}, {$sort:{_id:-1}}, {$group:{_id:'$serial',type:{$first:'$type'},sensors:{$first:'$sensors'},id:{$first:'$_id'}}} ]); Would get a list of all first found of each type. Edit The update will get the last inserted according to the _id.

Categories : Mongodb

MongoDB directoryperdb option
Yes, that should work just fine - as long as you shutdown MongoDB first before moving files around. If you are using a replica set, then you need to do it one by one, and make sure you follow the rolling "upgrades" procedure — ie, makes sure that a node is a secondary first before shutting it down.

Categories : Mongodb

How do I search a txt document for a word and write that word to a new document for reporting?
Something like: foreach(var line in File.ReadLines(filename) .Where(l => l.Contains("ERROR MESSAGE"))) { // Log line } Additionally if you need specific information inside the line you can use a Regex to capture the information. I cannot provide a better example without more information.

Categories : C#

mongodb - one document in many collections
Try looking at the problem inside-out: Instead of having items inside categories, have the items list the categories they belong into. You'll be able to easily find all items that belong to a category (or even multiple categories), and there is no duplication nor any need to keep many instances of the same item updated. This can be very fast and efficient, especially if you index the list of categories. Check out multikey indexes.

Categories : Database

Add a value to an array in a MongoDB document
You're looking for the $push operator. $arrayValueToAdd = array ( '22' => 1 ); $collection->update( array('email' => $user['email']), array( '$push' => array( 'emailQueries' => $arrayValueToAdd ) ) );

Categories : PHP

How to sum every fields in a sub document of MongoDB?
You have made the classical mistake to have arbitrary field names. MongoDB is "schema-free", but it doesn't mean you don't need to think about your schema. Key names should be descriptive, and in your case, f.e. "S2" does not really mean anything. In order to do most kinds of queries and operations, you will need to redesign you schema to store your data like this: _id:... Segment:[ { field: "S1", value: 1 }, { field: "S2", value: 5 }, { field: "Sn", value: 10 }, ] You can then run your query like: db.collection.aggregate( [ { $unwind: "$Segment" }, { $group: { _id: '$_id', sum: { $sum: '$Segment.value' } } } ] ); Which then results into something like this (with the only document from your question): { "result" : [ {

Categories : Mongodb

query the value of a sub document in mongodb
You can use dot notation in the projection parameter of find to do this. In the shell: db.test.find( {_id : ObjectId("5207fe359b88bfa6f90a82b0")}, {'members.5207fe359b88bfa6f90a82af': 1, _id: 0}) Returns: { "members": { "5207fe359b88bfa6f90a82af": [ "Admin", "User" ] } }

Categories : Mongodb

How to get None Option from salatDAO when mongodb gives error
I'll give you two answers to this problem. The first one requires a slight change your approach. If the Salat DAO functionality is potentially throwing exceptions on insert, you might want to consider changing the createUser function to return a Try[Option[ObjectId]] instead and rework it like so: def createUser (email: String, password: String):Try[Option[ObjectId]] = { val newUser = User(email = email, password = password) Try(userDAO.insert(newUser)) } Now the caller knows that the result will be one of three things: a Success(Some(objectId)), a Success(None) (not sure when this will happen but since it's an Option, you have to be able to handle it) or a Failure wrapping some exception. This way you could even pattern match on the exception in the Failure to make sure it's t

Categories : Mongodb

mongodb - mongoimport stopOnError option
The stopOnError explicitly skips the duplicate key error as can be seen from the source at https://github.com/mongodb/mongo/blob/master/src/mongo/tools/import.cpp#L314. I have filed https://jira.mongodb.org/browse/DOCS-1709 to have the documentation specify this.

Categories : Mongodb

Opening excel document created by php
This is because the file is actually basically just a CSV file with an XLS extension to make it open in Excel. See this Microsoft doc for more information: http://support.microsoft.com/kb/948615 - it happens in new versions of Excel. Older ones will happily export them. The reason for doing it this way was because it is so much simpler to export a CSV file than an Excel one. I'd like to write a proper Excel exporter sometime, but that will take time to read and understand the Excel file format, and I've not had a chance to do that yet. One option is simply to rename the file name to .csv, and keep the user interface as saying that it is an Excel file (Excel is quite happy to read csv files). Given that Windows tends to hide the file extension, this seems like a fairly attractive option.

Categories : PHP

Parse dynamically created XML document in c#
I can't figure out the Type of dialDataSrc but this should get you on your way: var listOfparameters = DialsDoc .Element("Parameters") .Elements() .Select(p => MyCreateParam((string) p.Element("Name"), (string) p.Element("Type"))) .ToList(); With a little helper method to figure out the DbType etc: private SqlParameter MyCreateParam(string name, string _type) { ... }

Categories : C#

mongodb update with many embedd document
When you call Save, base on your [BsonId] field driver decides what to do with this document: if document with Id does not exist in collection, it will insert this document if document with Id exists in collection, it will update this document (based on your Id). Update means it will replace all fields with the new fields from your entity Here is an example how save method works in pseudocode (the same as in C# driver): function save( doc ) { if( doc["_id"] ) { update( {_id: doc["_id"] }, doc, { upsert: true } ); } else { insert(doc); } }

Categories : Mongodb

how to add and delete a sub document in MongoDB shell?
You are looking for $set and $unset. You would use it like so: db.collection.update({name: "John"}, {$unset: {"address.street": ""}, $set: {"address.zip": 94105}}) There is not a wildcard field name matcher in MongoDB. I don't anticipate one in the future.

Categories : Mongodb

Can I select an array from every document in mongodb?
You may need to use the Aggregation Framework to accomplish this. Specifically, $unwind. For example: db.blogPost.aggregate( { $project: { _id : 0 , comments: 1 } }, { $unwind: "$comments" } ); Alternatively, if viable in your situation, you could just perform the concatenation of comments at the application level instead of database level, making the Mongo query simply that of over all blog posts.

Categories : Mongodb

delete element from document in MongoDB using C#
After searching on the web for a while, i found it myself. For those who want to know my solution: for (int j = 0 ; j < idlist.Count ; j++) { var queryDeleteValue = new QueryDocument("_id", idlist[j]); var update = Update.Unset("Flash_point"); collectionInput.Update(queryVerwijderValue, update); } So, first of all, i have a query-variable that selects the right document. Then i make an update variable where i unset the element 'Flash_point'. The last step is to do the actual update (with the parameters 'queryDeleteValue' and 'update').

Categories : C#

Single qoute in MongoDB document
I had same problem before 2 days and i have solved it using below query. below is the solution for me. SELECT * FROM tags WHERE `name` = 'limit\''s' LIMIT 0 , 30 SEE HERE

Categories : PHP

mongodb c# how to work with BSON document
There are a few ways, but here's one: // build some test data BsonArray dataFields = new BsonArray { new BsonDocument { { "ID" , ObjectId.GenerateNewId()}, { "NAME", "ID"}, {"TYPE", "Text"} } }; BsonDocument nested = new BsonDocument { { "name", "John Doe" }, { "fields", dataFields }, { "address", new BsonDocument { { "street", "123 Main St." }, { "city", "Madison" }, { "state", "WI" }, { "zip", 53711} } } }; // grab the address from the document, // subdocs as a BsonDocument var address = nested["address"].AsBsonDocument; Console.WriteLine(address["city"].AsString); // or, jump straight to the value ... Console.WriteLine(nested["address"]["city"].AsString); // loop through the fields array

Categories : C#

How to push a new document in mongodb but only if it does not exist?
Use the $addToSet operator. It ensures that the value will be added if is not in the array already. Basically: exports.addContactPost = function(req, res, err) { User.findByIdAndUpdate(req.signedCookies.userid, { $addToSet: {friendRequest: req.body.friendRequest} }, function(err) { if(err) { console.log(err); return console.log('error'); } else { console.log('postsuccess'); res.json({response: true}); } }); };

Categories : Node Js

With cakephp2.3 and mongoDB how to add array in a document?
the answer to the question was: public function salvar($name,$size,$id){ $this->mongoNoSetOperator = '$push'; // fixed array data structure $susp = array( "_id" => $id, "images"=> array( array( 'id' => new MongoId(), 'name' => $name, 'size' => $size ) ) ); return $this->save($susp); } Note: Thank Garamon from github, by clear and objective answers.

Categories : Mongodb

How to remove a document referenced by an id in mongoDB from php?
"To remove a document based on its ID, you need to ensure that you pass the ID as a MongoID object rather than just a string:" Normally what the PHP manual states is true but not for you. You have changed the type of your _id to something other than an ObjectId (aka a MongoId). With this in mind you need to search by that other object which is a MongoInt32: $db->collection->remove(array('_id'=>new MongoInt32(1)))

Categories : PHP

Find document with its surroundings in MongoDB
You can not do this in one query, but you will have to use three instead: // current r = db.so.findOne( { _id: 6 } ); // previous 2 db.so .find( { publishDate: { $lte: r.publishDate }, _id: { $ne: 6 } ) .sort( { publishDate: -1 } ) .limit( 2 ); // next 2 db.so .find( { publishDate: { $gte: r.publishDate }, _id: { $ne: 6 } ) .sort( { publishDate: 1 } ) .limit( 2 );

Categories : Mongodb

Finding embedded document without _id in MongoDB
Yes, you can. Use the dot notation to specify the property of the embedded document you are looking for. Let's say you have a collection for persons with docs like this: { _id:123, name:"john", address: { Street:"any", zip:1234 } } Then you can find a person querying by an address field like this: db.persons.find("address.zip":1234, ...) Just consider that it won't give you only the embedded doc, but the entire document (person in this case)

Categories : Mongodb

Not able to delete document from Mongodb database with PHP
_id field is not a string in mongodb, it's an object of ObjectId class; instead of $id = (array("_id" => $_POST["id"])); you should use $id = (array("_id" => new MongoId($_POST["id"])));

Categories : PHP

MongoDb c# update array in document
Working sample code for appending a list of strings to an existing list of strings using a strongly-typed Push: class Event { public ObjectId Id { get; set; } public string Name { get; set; } public List<string> Participants { get; set; } } class Program { static void Main(string[] args) { MongoClient client = new MongoClient("mongodb://localhost/test"); var db = client.GetServer().GetDatabase("test"); var collection = db.GetCollection("events"); var event0 = new Event { Name = "Birthday Party", Participants = new List<string> { "Jane Fonda" } }; collection.Insert(event0); collection.Update(Query.EQ("_id", event0.Id), Update<Event>.PushAll(p => p.Participants,

Categories : C#

how to update a mongodb document from node.js?
Change this line: ({_id:doc._id},$set:{scores:zz}); To: ({_id:doc._id}, { $set:{scores:zz}} ); This should also probably be wrapped with a callback, to catch errors: db.schools.update({_id:doc._id}, {$set:{scores:zz}}, function(err, result) { if (err) //do something. });

Categories : Node Js

Programmatically select newly-created option with jQuery?
Maybe this will help: option = '<option selected="selected" value="' + response.id + '">' + response.title + '</option>'; select.append(option); Update: after reading your comment I believe this isn't a multi select list. In that case you'll have to do this before the above code to have only one selected option: $("select option").each(function(){ $(this).removeAttr("selected"); });

Categories : Jquery

Need to retain dynamically created option in combo box using Knockout.js
If you're using knockout (which I can't actually see) all you need to do is bind your select box to an observable array and when you need to add a new item just push it onto the array and knockout will add it to the list for you. Knockout should essentially replace that script you've included with a lot less, much more simplistic code.

Categories : Javascript

mongodb performance with large array within a document
It sounds like those 510,000 employees might actually belong to a different class or entity than simply "employees managed by supervisor 5555". Call this class "A". The employees would be marked as belonging to class "A" (and possibly other classes), and 5555 would be marked as the manager of "A", but not of the individual employees. That is under the assumption that it is more likely for the manager of class "A" to change, than all 510,000 employees falling out of class "A".

Categories : Mongodb

create mongodb document with subdocuments atomically?
Update with upsert=true can be used to perform an atomic "insert or update" (http://docs.mongodb.org/manual/core/update/#update-operations-with-the-upsert-flag). For instance if we want to make sure a document in Front collection with specific url is inserted exactly once, we could run something like: db.Front.update( {url: 'http://example.com'}, {$set: { url: 'http://example.com'}, found: true } ) Operations on a single document in MongoDB are always atomic. If you make updates that span over multiple documents, then no atomicity is guaranteed. In such cases, you can ask yourself: do I really need the operations to be atomic? If the answer is no, then you probably will find your way around working with potentially unconsistent data. If the answer is yes and y

Categories : Node Js



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