How to parse a variable into firebase.database().ref().set({...}) - firebase

i am trying to add firebase into my react-native application, and have the following code:
_saveFile(fileName){
var userPath = "/Users/Johnny/files/";
var storageString = ("Johnny Johnson\n"+ date + "\n" +
this.state.text);
var name = fileName;
firebase.database().ref(userPath).set({
name : storageString
})
}
But as you can probably guess, this isn't getting the name variable and storing it as the key. It is simply storing it in the database as..
Users -> Johnny -> files -> {name: "whatever the string was i saved"}
and then simply overriding it every time i try and make a new file. Just wondering how i go about parsing in this fileName variable? It is getting the child value correctly - which is why i am confused.
Any help would be appreciated, i'm pretty new to this.

If you put brackets around name it will use the name variable instead of creating a key called name.
firebase.database().ref(userPath).set({
[name] : storageString
})

Related

Groovy script to change all users to uppercase

I'm trying to change all user names with in a magnolia application to uppercase since we are having case sensitivity issues with our login.
I wrote this groovy script, following an example used to reset passwords to "", to capture the users and change them uppercase but it appears the name property is not being set.
https://documentation.magnolia-cms.com/display/WIKI/Reset+all+passwords
import info.magnolia.jcr.util.NodeUtil
import info.magnolia.jcr.predicate.NodeTypePredicate
import info.magnolia.jcr.util.NodeTypes
session = ctx.getJCRSession("users")
users = NodeUtil.collectAllChildren(session.getNode("/public"), new NodeTypePredicate(NodeTypes.User.NAME))
users.each() {
changedName = it.name.toUpperCase();
it.setProperty("name", changedName)
it.save();
println "1 " + changedName;
println "2 " + it.name;
}
session.save();
When I'm checking it.name it is return how they are stored in the mangolia, and not as all uppercase and they are also not being changed in the security app when looking at the username.
import info.magnolia.jcr.util.NodeUtil
import info.magnolia.jcr.predicate.NodeTypePredicate
import info.magnolia.jcr.util.NodeTypes
session = ctx.getJCRSession("users")
users = NodeUtil.collectAllChildren(session.getNode("/admin"), new NodeTypePredicate(NodeTypes.User.NAME))
users.each() {
name = it.name
changedName = it.name.toUpperCase();
it.setProperty("name", changedName)
it.setProperty("jcrName", changedName)
it.save()
NodeUtil.renameNode(it, changedName)
it.getNode("acl_users").getNodes().each { node ->
newPath = node.getProperty("path").getString().replace(name, changedName)
node.setProperty("path", newPath)
node.save()
}
}
session.save()
Hey, maybe this is what u are looking for. You need to change the Node name and the jcrName in my Version I iterate over the acl_users Node and change the path of each. Hope this works for you.
IIRC there's 3 things you need to change.
name is one of them, then there's jcrName property and then you need to change the name of the node itself. At least if you want to see it in security app that way.
For the login itself, what you did should be already sufficient.
Try to use the setProperty method of PropertyUtil.
You have to extract all nodes that you need and then loops through them. Supposing that the variable node is the Node you want to change the name, do this:
String newName = StringUtils.upperCase(PropertyUtil.getString(node, "jcrName"));
PropertyUtil.setProperty(node, "jcrName", newName);
jcrName is the property you need to overwrite. Wrap the code into a try/catch block and here we go.
Hope it helps.

How to get the generated key of the saveValue method in Polymerfire?

So I'm using this method saveValue and only using the path parameter. The method is generating a unique key and data is stored while I'm inserting text in my input fields...
My question now is: How can I get to know what the new key is?
Regards, Peter
This is an old question but I just came across this issue. The answer is that the new path is saved to the path property of the firebase-document used to call saveValue.
<firebase-document id="NewUserSync"></firebase-document>
...In some click handler....
this.$.NewUserSync.path = null;
this.$.NewUserSync.data = OrgData;
this.$.NewUserSync.saveValue(`/Customer_Orgs/`).then(resp => {
console.log(this.$.NewUserSync.path);
// /Customer_Orgs/-LH_pEzgWJpv3mpYYTuA
})

Change a space to a + in order to complete an api in flex

I'm trying to make a search form to use on an api. However when the user types in the search field more then one name I want it to break the string into pieces and make a new string with a + between every keyword. I have no idea how to do this however.
Try this
var searchString:String = "nameOne nameTwo nameThree";
var whiteSpacePattern:RegExp = /\s+/g;
var replacedString:String = searchString.replace(whiteSpacePattern, "+");
trace(replacedString); // nameOne+nameTwo+nameThree
More information about String.replace : http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f00.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7ef1

Accessing the query string value using ASP.NET

I have been trying to find the question to my answer but I'm unable to and finally I'm here. What I want to do is access the value passed to a webpage (GET, POST request) using asp.net. To be more clear, for example:
URL: http://www.foobar.com/SaleVoucher.aspx?sr=34
Using asp.net I want to get the sr value i.e 34.
I'm from the background of C# and new to ASP.NET and don't know much about ASP.NET.
Thanx.
Can you refer to this QueryString
Here he says how to access the query string using:
Request.Url.Query
That is not called a Header, but the Query String.
the object document.location.search will contain that and the javascript to get any query string value based on the key would be something like:
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
code from other question: https://stackoverflow.com/a/901144/28004

meteor 0.5.7: how to handle/use Meteor.Collection.ObjectID?

I have updated my meteor yesterday and tried using the new Meteor.Collection.ObjectID.
But since with no success. First i updated my collections in this way:
myCollection = new Meteor.Collection('mycollection', {idGeneration: 'MONGO'}
Now, normal new inserts have an _id like Wi2RmR6CSapkmmdfn... (?)
Then i have a collection with an array included. I like to have an unique id for every object in this array. So i $push an object with a field like id: new Meteor.Collection.ObjectID() into my array. The result in the database is like this: ObjectId("5b5fc278305d406cc6c33756"). (This seems to be normal.)
But later i want to update my pushed object, if the id equals an id, which i stored as data attribute in an html tag before.
var equals = EJSON.equals(dbId, htmlId); (This results every time in false. So i logged the values dbId and htmlId into the console with console.log(typeof dbId, dbId);)
The values of this two variables is as follows:
object { _str: 'a86ce44f9a46b99bca1be7a9' } (dbId)
string ObjectID("a86ce44f9a46b99bca1be7a9") (htmlId; this seems to be correct, but why is a custom type a string?)
How to use the Meteor.Collection.ObjectID correct?
When placing your htmlId in your html you need to put it in as a string and not as an object, remember _id is an object now, handlebars is guessing and using toString() & thats why it shows up as ObjectID("...").
So if you're using {{_id}} in your html you now need to use {{_id.toHexString}} to properly extract the string part of it out
When you extract this html value with your javascript you need to make it back into an objectid:
js:
var valuefromhtml = "a86ce44f9a46b99bca1be7a9"; //Get with Jquery,DOM,etc
htmlId = new Meteor.Collection.ObjectID(valuefromhtml); //see: http://docs.meteor.com/#collection_object_id
EJSON.equals(htmlId, dbId); //Should be true this time

Resources